@@ -366,60 +366,38 @@ def test_isna() -> None:
366
366
assert check (assert_type (pd .isna (np_nat ), bool ), bool )
367
367
assert not check (assert_type (pd .notna (np_nat ), bool ), bool )
368
368
369
- # Check TypeGuard type narrowing functionality
370
- # TODO: Due to limitations in TypeGuard spec, the true annotations are not always viable
371
- # and as a result the type narrowing does not always work as it intuitively should
372
- # There is a proposal being floated for a StrictTypeGuard that will have more rigid narrowing semantics
373
- # In the test cases below, a commented out assertion will be included to document the optimal test result
369
+ # Check TypeIs type narrowing functionality
374
370
nullable1 : str | None | NAType | NaTType = random .choice (
375
371
["value" , None , pd .NA , pd .NaT ]
376
372
)
377
373
if pd .notna (nullable1 ):
378
374
check (assert_type (nullable1 , str ), str )
379
375
if not pd .isna (nullable1 ):
380
- # check(assert_type(nullable1, str), str) # TODO: Desired result (see comments above)
381
- check (assert_type (nullable1 , Union [str , NaTType , NAType , None ]), str )
376
+ check (assert_type (nullable1 , str ), str )
382
377
if pd .isna (nullable1 ):
383
378
assert_type (nullable1 , Union [NaTType , NAType , None ])
384
379
if not pd .notna (nullable1 ):
385
- # assert_type(nullable1, Union[NaTType, NAType, None]) # TODO: Desired result (see comments above)
386
- assert_type (nullable1 , Union [str , NaTType , NAType , None ])
380
+ assert_type (nullable1 , Union [NaTType , NAType , None ])
387
381
388
382
nullable2 : int | None = random .choice ([2 , None ])
389
383
if pd .notna (nullable2 ):
390
384
check (assert_type (nullable2 , int ), int )
391
385
if not pd .isna (nullable2 ):
392
- # check(assert_type(nullable2, int), int) # TODO: Desired result (see comments above)
393
- check (assert_type (nullable2 , Union [int , None ]), int )
386
+ check (assert_type (nullable2 , int ), int )
394
387
if pd .isna (nullable2 ):
395
- # check(assert_type(nullable2, None), type(None)) # TODO: Desired result (see comments above)
396
- check (assert_type (nullable2 , Union [NaTType , NAType , None ]), type (None ))
388
+ check (assert_type (nullable2 , None ), type (None ))
397
389
if not pd .notna (nullable2 ):
398
- # check(assert_type(nullable2, None), type(None)) # TODO: Desired result (see comments above)
399
- # TODO: MyPy and Pyright produce conflicting results:
400
- # assert_type(nullable2, Union[int, None]) # MyPy result
401
- # assert_type(
402
- # nullable2, Union[int, NaTType, NAType, None]
403
- # ) # Pyright result
404
- pass
390
+ check (assert_type (nullable2 , None ), type (None ))
405
391
406
392
nullable3 : bool | None | NAType = random .choice ([True , None , pd .NA ])
407
393
if pd .notna (nullable3 ):
408
394
check (assert_type (nullable3 , bool ), bool )
409
395
if not pd .isna (nullable3 ):
410
- # check(assert_type(nullable3, bool), bool) # TODO: Desired result (see comments above)
411
- check (assert_type (nullable3 , Union [bool , NAType , None ]), bool )
396
+ check (assert_type (nullable3 , bool ), bool )
412
397
if pd .isna (nullable3 ):
413
- # assert_type(nullable3, Union[NAType, None]) # TODO: Desired result (see comments above)
414
- assert_type (nullable3 , Union [NaTType , NAType , None ])
398
+ assert_type (nullable3 , Union [NAType , None ])
415
399
if not pd .notna (nullable3 ):
416
- # assert_type(nullable3, Union[NAType, None]) # TODO: Desired result (see comments above)
417
- # TODO: MyPy and Pyright produce conflicting results:
418
- # assert_type(nullable3, Union[bool, NAType, None]) # Mypy result
419
- # assert_type(
420
- # nullable3, Union[bool, NaTType, NAType, None]
421
- # ) # Pyright result
422
- pass
400
+ assert_type (nullable3 , Union [NAType , None ])
423
401
424
402
425
403
# GH 55
0 commit comments