File tree 4 files changed +8
-27
lines changed 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:
718
718
class AsyncGenerator (Generator ):
719
719
"""Special node representing an async generator."""
720
720
721
+ def __init__ (self , * args , ** kwargs ):
722
+ super ().__init__ (* args , ** kwargs )
723
+ AsyncGenerator .special_attributes = objectmodel .AsyncGeneratorModel ()
724
+
721
725
def pytype (self ) -> Literal ["builtins.async_generator" ]:
722
726
return "builtins.async_generator"
723
727
Original file line number Diff line number Diff line change @@ -728,11 +728,7 @@ def __init__(self):
728
728
# Append the values from the AGeneratorType unto this object.
729
729
super ().__init__ ()
730
730
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" ]
736
732
for name , values in generator .locals .items ():
737
733
method = values [0 ]
738
734
if isinstance (method , nodes .FunctionDef ):
Original file line number Diff line number Diff line change @@ -627,9 +627,8 @@ def _astroid_bootstrapping() -> None:
627
627
col_offset = 0 ,
628
628
end_lineno = 0 ,
629
629
end_col_offset = 0 ,
630
- parent = nodes . Unknown () ,
630
+ parent = astroid_builtin ,
631
631
)
632
- _GeneratorType .parent = astroid_builtin
633
632
generator_doc_node = (
634
633
nodes .Const (value = types .GeneratorType .__doc__ )
635
634
if types .GeneratorType .__doc__
@@ -651,9 +650,8 @@ def _astroid_bootstrapping() -> None:
651
650
col_offset = 0 ,
652
651
end_lineno = 0 ,
653
652
end_col_offset = 0 ,
654
- parent = nodes . Unknown () ,
653
+ parent = astroid_builtin ,
655
654
)
656
- _AsyncGeneratorType .parent = astroid_builtin
657
655
async_generator_doc_node = (
658
656
nodes .Const (value = types .AsyncGeneratorType .__doc__ )
659
657
if types .AsyncGeneratorType .__doc__
Original file line number Diff line number Diff line change @@ -1454,7 +1454,7 @@ def test(self):
1454
1454
assert bool (inferred .is_generator ())
1455
1455
1456
1456
1457
- class AsyncGeneratorTest :
1457
+ class AsyncGeneratorTest ( unittest . TestCase ) :
1458
1458
def test_async_generator (self ):
1459
1459
node = astroid .extract_node (
1460
1460
"""
@@ -1472,23 +1472,6 @@ async def a_iter(n):
1472
1472
assert inferred .pytype () == "builtins.async_generator"
1473
1473
assert inferred .display_type () == "AsyncGenerator"
1474
1474
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
-
1492
1475
1493
1476
def test_f_string_correct_line_numbering () -> None :
1494
1477
"""Test that we generate correct line numbers for f-strings."""
You can’t perform that action at this time.
0 commit comments