Skip to content
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

Unable to suppress typechecker nitpicks #11

Closed
jaraco opened this issue Aug 21, 2024 · 3 comments
Closed

Unable to suppress typechecker nitpicks #11

jaraco opened this issue Aug 21, 2024 · 3 comments

Comments

@jaraco
Copy link
Owner

jaraco commented Aug 21, 2024

When merging 3841656 from jaraco/skeleton#136, the tests started failing.

____________________________ backports/__init__.py _____________________________
1: error: Unused "type: ignore" comment  [unused-ignore]
_________________________________ test session _________________________________
mypy exited with status 1.
_____________________ backports/entry_points_selectable.py _____________________
24: error: Unused "type: ignore" comment  [unused-ignore]
26: error: "type: ignore" comment without error code (consider "type: ignore[attr-defined, no-redef]" instead)  [ignore-without-code]
31: error: Unused "type: ignore" comment  [unused-ignore]
35: error: Unused "type: ignore" comment  [unused-ignore]
38: error: Unused "type: ignore" comment  [unused-ignore]
39: error: Unused "type: ignore" comment  [unused-ignore]
41: error: "type: ignore" comment without error code (consider "type: ignore[import-not-found]" instead)  [ignore-without-code]

I fixed all the errors on Python 3.12 in 6413a18, but now tests fail on Python 3.8 and 3.9.

_____________________ backports/entry_points_selectable.py _____________________
38: error: Name "metadata" already defined (by an import)  [no-redef]
39: error: Incompatible import of "distributions" (imported name has type overloaded function, local name has type "Callable[[KwArg(Any)], Iterable[importlib_metadata.Distribution]]")  [assignment]
39: error: Incompatible import of "EntryPoint" (imported name has type "Type[importlib.metadata.EntryPoint]", local name has type "Type[importlib_metadata.EntryPoint]")  [assignment]
41: error: Unused "type: ignore" comment  [unused-ignore]

@Avasam Can you work out a solution to get mypy checks to pass on all Python versions?

@Avasam
Copy link
Contributor

Avasam commented Aug 21, 2024

Just by reading the commit, my initial guess is that you have dependencies (or versions of such) that are installed in some Python environments but not others.
You can either:

You might find this comment relevant: pypa/setuptools#4586 (comment)

Footnotes

  1. I actually do recommend setting python_version in the configs so that editors work on the oldest supported Python version by default. BUT only if you have your CI explicitly pass the --python-version flag to override it

@jaraco
Copy link
Owner Author

jaraco commented Aug 21, 2024

  • Use sys.version_info and sys.platform checks instead of try-except-ing imports (most recommended when possible)

I can't use this technique. The implementation needs to remain unchanged.

  • Install all dependencies unconditionally in your type testing environment

I didn't think this would work - because importlib_metadata was already installed in Python 3.8, but it does seem to shift the problem such that other exclusions can be made to work.

  • Lock mypy's python_version to a specific version (not recommended1, setuptools only does it currently because of distutils and

I'll probably disable mypy checks before going into this kind of customization.

@jaraco jaraco closed this as completed in 702dc71 Aug 21, 2024
@jaraco
Copy link
Owner Author

jaraco commented Aug 21, 2024

I'm hoping this fix also works for jaraco/oathtool#4.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants