gh-99535: Add test for inheritance of annotations and update documentation (#99990)

This commit is contained in:
MonadChains 2022-12-24 21:07:14 +01:00 committed by GitHub
parent e4b43ebb3a
commit f5b7b19bf1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 32 additions and 0 deletions

View file

@ -415,6 +415,28 @@ class GrammarTests(unittest.TestCase):
x: int
x.y: list = []
def test_annotations_inheritance(self):
# Check that annotations are not inherited by derived classes
class A:
attr: int
class B(A):
pass
class C(A):
attr: str
class D:
attr2: int
class E(A, D):
pass
class F(C, A):
pass
self.assertEqual(A.__annotations__, {"attr": int})
self.assertEqual(B.__annotations__, {})
self.assertEqual(C.__annotations__, {"attr" : str})
self.assertEqual(D.__annotations__, {"attr2" : int})
self.assertEqual(E.__annotations__, {})
self.assertEqual(F.__annotations__, {})
def test_var_annot_metaclass_semantics(self):
class CMeta(type):
@classmethod