Disable type hint

Is there a way to disable this feature? Sometimes when I import someone’s module, it’s really annoying.

# type: ignore

Either after the import.
Or at the top of your source file.

I’m working on Python3.8. The file below fails to work.

# type: ignore
def foo(name: str | None = None):
print(name)
foo(‘Bob’)

Traceback (most recent call last):
File “test_type_ignore.py”, line 2, in
def foo(name: str | None = None):
TypeError: unsupported operand type(s) for |: ‘type’ and ‘NoneType’

Python did not support Union types (str | None) until 3.10. Prior to that you need to use typing.Union[str, None].

The version of the code you are using does not support python 3.8. I don’t believe there is any way to disable this to work around it.

One can add from __future__ import annotations to the top of the script in order to skip the evaluation of annotations in unsupported versions of Python. This allows Python 3.10 style annotations in Python 3.8.

Missing annotations can be fetched from typing_extensions and type checkers can verify that specific versions of Python are supported.

That library simply does not support Python 3.8 unless those changes are made.

Note that Python 3.9 has reached end-of-life, there’s often little motivation for library authors to support these older versions of Python.

```from __future__ import annotations``` is the easiest solution! Thank you, Kyle.