-
Notifications
You must be signed in to change notification settings - Fork 42
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
mypy errors with suggested tomli
/tomllib
compatibility layer
#219
Labels
enhancement
New feature or request
Comments
Try:
|
hauntsaninja
added a commit
that referenced
this issue
Apr 17, 2023
Fixes #219 Static type checkers are able to understand checks against sys.version_info much better than try-except. In general, if type checkers tried to handle conditional imports fancily, this would result in unsoundness. Another reason is that you may have tomli conditionally installed based on Python version, in which case a type checker would not even have a way of knowing what tomli is.
This sounds like a bug in mypy: python/mypy#13914 |
hukkin
added a commit
that referenced
this issue
Dec 12, 2023
* Use sys.version_info in compatibility layer Fixes #219 Static type checkers are able to understand checks against sys.version_info much better than try-except. In general, if type checkers tried to handle conditional imports fancily, this would result in unsoundness. Another reason is that you may have tomli conditionally installed based on Python version, in which case a type checker would not even have a way of knowing what tomli is. * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Taneli Hukkinen <[email protected]>
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hello, I'm attempting to write forward-looking code which uses the documented
tomli
/tomllib
compatibility layer:When I check this code with mypy, I am met with the following errors:
(
Python 3.10.9
,mypy 0.991
)Line 2: The
tomllib
import error is expected since I am running Python 3.10 (and it was added to the standard lib in 3.11). This is resolved by ignoring the import error.Line 4: The
Name "tomllib" already defined
error is resolved by upgrading tomypy 1.2.0
or ingoring the redef error.tomllib
isAny
, so all functions and their return values areAny
as well.When the compatibility layer is not used, the typing is correctly provided (presumably via typeshed, although I can't find it?)
Is this a limitation of mypy that we have to live with, or can the pattern be somehow updated to resolve these issues?
The text was updated successfully, but these errors were encountered: