diff options
Diffstat (limited to 'basics/python/circular')
| -rw-r--r-- | basics/python/circular/a.py | 13 | ||||
| -rw-r--r-- | basics/python/circular/b.py | 19 | ||||
| -rw-r--r-- | basics/python/circular/c.py | 10 |
3 files changed, 42 insertions, 0 deletions
diff --git a/basics/python/circular/a.py b/basics/python/circular/a.py new file mode 100644 index 0000000..b32c70d --- /dev/null +++ b/basics/python/circular/a.py @@ -0,0 +1,13 @@ + + +from typing import TYPE_CHECKING +if TYPE_CHECKING: + from b import B + + +class A: + def foo(self, b: 'B'): + return 2*b.foo() + + def t(self): + print('A.t()') diff --git a/basics/python/circular/b.py b/basics/python/circular/b.py new file mode 100644 index 0000000..643e2f7 --- /dev/null +++ b/basics/python/circular/b.py @@ -0,0 +1,19 @@ + + +# from typing import TYPE_CHECKING +# if TYPE_CHECKING: +from a import A + + +class B: + + def __init__(self): + self.a_items = [] + + def append(self, a: 'A'): + a.t() + self.a_items.append(a) + + def foo(self): + return 5 + diff --git a/basics/python/circular/c.py b/basics/python/circular/c.py new file mode 100644 index 0000000..b17402d --- /dev/null +++ b/basics/python/circular/c.py @@ -0,0 +1,10 @@ + +from b import B +from a import A + + +a_inst = A() +b_inst = B() + +print(a_inst.foo(b_inst)) +b_inst.append(a_inst) |
