Summary
If python-version is set to 3.9, red-knot emits an error on the following code:
import sys
if sys.version_info >= (3, 11):
from typing import Self # error: Module `typing` has no member `Self`
Red-knot correctly understands that the code is okay if python-version is set to 3.11 or higher. However, this kind of sys.version_info-guarded import is reasonably common in code that aims to support old Python versions -- e.g. lots of libraries do things like this, so that they can have typing_extensions only as a dependency on old Python versions:
import sys
if sys.version_info >= (3, 11):
from typing import Self
else:
from typing_extensions import Self
Mypy and pyright both support this pattern, so I think it's quite important for red-knot to also support it (though it's perhaps not something that's essential to do before the alpha release).
Summary
If
python-versionis set to 3.9, red-knot emits an error on the following code:Red-knot correctly understands that the code is okay if
python-versionis set to 3.11 or higher. However, this kind ofsys.version_info-guarded import is reasonably common in code that aims to support old Python versions -- e.g. lots of libraries do things like this, so that they can havetyping_extensionsonly as a dependency on old Python versions:Mypy and pyright both support this pattern, so I think it's quite important for red-knot to also support it (though it's perhaps not something that's essential to do before the alpha release).