@@ -366,60 +366,38 @@ def test_isna() -> None:
366366 assert check (assert_type (pd .isna (np_nat ), bool ), bool )
367367 assert not check (assert_type (pd .notna (np_nat ), bool ), bool )
368368
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
374370 nullable1 : str | None | NAType | NaTType = random .choice (
375371 ["value" , None , pd .NA , pd .NaT ]
376372 )
377373 if pd .notna (nullable1 ):
378374 check (assert_type (nullable1 , str ), str )
379375 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 )
382377 if pd .isna (nullable1 ):
383378 assert_type (nullable1 , Union [NaTType , NAType , None ])
384379 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 ])
387381
388382 nullable2 : int | None = random .choice ([2 , None ])
389383 if pd .notna (nullable2 ):
390384 check (assert_type (nullable2 , int ), int )
391385 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 )
394387 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 ))
397389 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 ))
405391
406392 nullable3 : bool | None | NAType = random .choice ([True , None , pd .NA ])
407393 if pd .notna (nullable3 ):
408394 check (assert_type (nullable3 , bool ), bool )
409395 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 )
412397 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 ])
415399 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 ])
423401
424402
425403# GH 55
0 commit comments