Ask Your Question

Revision history [back]

venv3.7 and typing

How to use typing in debugging?

Attempting to use * from typing import Generator * or * from typing import Dict * in the code results in an error.

Python 3.7.5 (tags/v3.7.5:5c02a39a0b, Oct 14 2019, 23:09:19) [MSC v.1916 32 bit (Intel)]
Type "help", "copyright", "credits" or "license" for more information.
>>> from typing import Generator
Traceback (most recent call last):
  Оболочка Python, prompt 1, строка 1
    # Used internally for debug sandbox under external interpreter
  Файл "c:\VENV37\Lib\site-packages\typing.py", строка 1357, из <module>    class Callable(extra=collections_abc.Callable, metaclass=CallableMeta):
  Файл "c:\VENV37\Lib\site-packages\typing.py", строка 1005, из __new__    self._abc_registry = extra._abc_registry
builtins.AttributeError: type object 'Callable' has no attribute '_abc_registry'

When you call the same code in the console, everything is fine.

(VENV37) AC..........OKS\ClassTasksPython
$ python
Python 3.7.5 (tags/v3.7.5:5c02a39a0b, Oct 14 2019, 23:09:19) [MSC v.1916 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> from typing import Generator
>>> def fib6(n: int) -> Generator[int, None, None]:
...     yield 0
...     if n > 0:
...         yield 1
...     last: int = 0
...     next: int = 1
...     for _ in range(1, n):
...         last, next = next, last + next
...         yield next
...
>>>
>>> if __name__ == '__main__':
...     for i in fib6(50):
...         print(i)
...
0
1
1
2
3
5
8
13
21

venv3.7 and typing

How to use typing in debugging?

Attempting to use * from typing import Generator * or * from typing import Dict * in the code results in an error.

Python 3.7.5 (tags/v3.7.5:5c02a39a0b, Oct 14 2019, 23:09:19) [MSC v.1916 32 bit (Intel)]
Type "help", "copyright", "credits" or "license" for more information.
>>> from typing import Generator
Traceback (most recent call last):
  Оболочка Python, prompt 1, строка 1
    # Used internally for debug sandbox under external interpreter
  Файл "c:\VENV37\Lib\site-packages\typing.py", строка 1357, из <module>    class Callable(extra=collections_abc.Callable, metaclass=CallableMeta):
  Файл "c:\VENV37\Lib\site-packages\typing.py", строка 1005, из __new__    self._abc_registry = extra._abc_registry
builtins.AttributeError: type object 'Callable' has no attribute '_abc_registry'

When you call the same code in the console, everything is fine.

(VENV37) AC..........OKS\ClassTasksPython
$ python
Python 3.7.5 (tags/v3.7.5:5c02a39a0b, Oct 14 2019, 23:09:19) [MSC v.1916 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> from typing import Generator
>>> def fib6(n: int) -> Generator[int, None, None]:
...     yield 0
...     if n > 0:
...         yield 1
...     last: int = 0
...     next: int = 1
...     for _ in range(1, n):
...         last, next = next, last + next
...         yield next
...
>>>
>>> if __name__ == '__main__':
...     for i in fib6(50):
...         print(i)
...
0
1
1
2
3
5
8
13
21

venv3.7 and typing

How to use typing in debugging?

Attempting to use * from typing import Generator * or * from typing import Dict * in the code results in an error.

Python 3.7.5 (tags/v3.7.5:5c02a39a0b, Oct 14 2019, 23:09:19) [MSC v.1916 32 bit (Intel)]
Type "help", "copyright", "credits" or "license" for more information.
>>> from typing import Generator
Traceback (most recent call last):
  Оболочка Python, prompt 1, строка 1
    # Used internally for debug sandbox under external interpreter
  Файл "c:\VENV37\Lib\site-packages\typing.py", строка 1357, из <module>    class Callable(extra=collections_abc.Callable, metaclass=CallableMeta):
  Файл "c:\VENV37\Lib\site-packages\typing.py", строка 1005, из __new__    self._abc_registry = extra._abc_registry
builtins.AttributeError: type object 'Callable' has no attribute '_abc_registry'

When you call the same code in the console, everything is fine.

(VENV37) AC..........OKS\ClassTasksPython
$ python
Python 3.7.5 (tags/v3.7.5:5c02a39a0b, Oct 14 2019, 23:09:19) [MSC v.1916 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> from typing import Generator
>>> def fib6(n: int) -> Generator[int, None, None]:
...     yield 0
...     if n > 0:
...         yield 1
...     last: int = 0
...     next: int = 1
...     for _ in range(1, n):
...         last, next = next, last + next
...         yield next
...
>>>
>>> if __name__ == '__main__':
...     for i in fib6(50):
...         print(i)
...
0
1
1
2
3
5
8
13
21