-
-
Notifications
You must be signed in to change notification settings - Fork 636
refactor: remove redundant str casts for canonicalize_name #2295
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
base: main
Are you sure you want to change the base?
Conversation
The type NormalizedName is just a NewType of str so it's compatible with return-type str. This means casting it to a str is never required.
|
Heya Initially I did not understand why the mypy check was failing because However, when upgrading the pre-commit config to use the first pip version where canonicalize_name is typed v21.2, I opened a can of worms and Then I decided to give it a go on the latest pip-supported (25.3) -> So my question now is: Why was mypy's pip version pinned at 20.3.4? An easy fix for this PR is to just add a Any suggestions/ideas? To be complete, here is the log when using pre-commit with the newest pip |
Ok, checking the commit history on the file actually revealed that this was introduced initially to silence mypy going to v21. 1efce5f I am not sure what is the preferred way forward. |
|
Thanks for getting this moving! Our mypy situation right now is poor -- we're currently stuck on the version in pre-commit and, as you note, there's some work to be done to un-wedge it (we have some other issues about that, like #2200). However, I think we should be able to land this even without fixing the mypy setup yet. I think the right approach is to wrap # _packaging_compat.py
import typing as _t
if _t.TYPE_CHECKING:
def canonicalize_name(name: str) -> str: ...
else:
from pip._vendor.packaging.utils import canonicalize_nameThat way, the rest of the codebase can grab |
The type NormalizedName is just a NewType of str so it's compatible with return-type str. This means casting it to a str is never required.
no changelog needed
Contributor checklist
changelog.d/(seechangelog.d/README.mdfor instructions) or the PR text says "no changelog needed".Maintainer checklist
bot:chronographer:skiplabel.