File tree Expand file tree Collapse file tree 4 files changed +8
-27
lines changed
Expand file tree Collapse file tree 4 files changed +8
-27
lines changed Original file line number Diff line number Diff line change @@ -718,6 +718,10 @@ def __str__(self) -> str:
718718class AsyncGenerator (Generator ):
719719 """Special node representing an async generator."""
720720
721+ def __init__ (self , * args , ** kwargs ):
722+ super ().__init__ (* args , ** kwargs )
723+ AsyncGenerator .special_attributes = objectmodel .AsyncGeneratorModel ()
724+
721725 def pytype (self ) -> Literal ["builtins.async_generator" ]:
722726 return "builtins.async_generator"
723727
Original file line number Diff line number Diff line change @@ -728,11 +728,7 @@ def __init__(self):
728728 # Append the values from the AGeneratorType unto this object.
729729 super ().__init__ ()
730730 astroid_builtins = AstroidManager ().builtins_module
731- generator = astroid_builtins .get ("async_generator" )
732- if generator is None :
733- # Make it backward compatible.
734- generator = astroid_builtins .get ("generator" )
735-
731+ generator = astroid_builtins ["async_generator" ]
736732 for name , values in generator .locals .items ():
737733 method = values [0 ]
738734 if isinstance (method , nodes .FunctionDef ):
Original file line number Diff line number Diff line change @@ -627,9 +627,8 @@ def _astroid_bootstrapping() -> None:
627627 col_offset = 0 ,
628628 end_lineno = 0 ,
629629 end_col_offset = 0 ,
630- parent = nodes . Unknown () ,
630+ parent = astroid_builtin ,
631631 )
632- _GeneratorType .parent = astroid_builtin
633632 generator_doc_node = (
634633 nodes .Const (value = types .GeneratorType .__doc__ )
635634 if types .GeneratorType .__doc__
@@ -651,9 +650,8 @@ def _astroid_bootstrapping() -> None:
651650 col_offset = 0 ,
652651 end_lineno = 0 ,
653652 end_col_offset = 0 ,
654- parent = nodes . Unknown () ,
653+ parent = astroid_builtin ,
655654 )
656- _AsyncGeneratorType .parent = astroid_builtin
657655 async_generator_doc_node = (
658656 nodes .Const (value = types .AsyncGeneratorType .__doc__ )
659657 if types .AsyncGeneratorType .__doc__
Original file line number Diff line number Diff line change @@ -1454,7 +1454,7 @@ def test(self):
14541454 assert bool (inferred .is_generator ())
14551455
14561456
1457- class AsyncGeneratorTest :
1457+ class AsyncGeneratorTest ( unittest . TestCase ) :
14581458 def test_async_generator (self ):
14591459 node = astroid .extract_node (
14601460 """
@@ -1472,23 +1472,6 @@ async def a_iter(n):
14721472 assert inferred .pytype () == "builtins.async_generator"
14731473 assert inferred .display_type () == "AsyncGenerator"
14741474
1475- def test_async_generator_is_generator_on_older_python (self ):
1476- node = astroid .extract_node (
1477- """
1478- async def a_iter(n):
1479- for i in range(1, n + 1):
1480- yield i
1481- await asyncio.sleep(1)
1482- a_iter(2) #@
1483- """
1484- )
1485- inferred = next (node .infer ())
1486- assert isinstance (inferred , bases .Generator )
1487- assert inferred .getattr ("__iter__" )
1488- assert inferred .getattr ("__next__" )
1489- assert inferred .pytype () == "builtins.generator"
1490- assert inferred .display_type () == "Generator"
1491-
14921475
14931476def test_f_string_correct_line_numbering () -> None :
14941477 """Test that we generate correct line numbers for f-strings."""
You can’t perform that action at this time.
0 commit comments