1"""Module for testing the behavior of generics across different modules."""
2
3import sys
4from textwrap import dedent
5from typing import TypeVar, Generic, Optional
6
7
8if sys.version_info[:2] >= (3, 6):
9    exec(dedent("""
10    default_a: Optional['A'] = None
11    default_b: Optional['B'] = None
12
13    T = TypeVar('T')
14
15
16    class A(Generic[T]):
17        some_b: 'B'
18
19
20    class B(Generic[T]):
21        class A(Generic[T]):
22            pass
23
24        my_inner_a1: 'B.A'
25        my_inner_a2: A
26        my_outer_a: 'A'  # unless somebody calls get_type_hints with localns=B.__dict__
27    """))
28else:  # This should stay in sync with the syntax above.
29    __annotations__ = dict(
30        default_a=Optional['A'],
31        default_b=Optional['B'],
32    )
33    default_a = None
34    default_b = None
35
36    T = TypeVar('T')
37
38
39    class A(Generic[T]):
40        __annotations__ = dict(
41            some_b='B'
42        )
43
44
45    class B(Generic[T]):
46        class A(Generic[T]):
47            pass
48
49        __annotations__ = dict(
50            my_inner_a1='B.A',
51            my_inner_a2=A,
52            my_outer_a='A'  # unless somebody calls get_type_hints with localns=B.__dict__
53        )
54