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

fix #918: remove the need for importlib_metadata in general #929

Conversation

RonnyPfannschmidt
Copy link
Contributor

(broke python<=3.9)

closes #918

Copy link

@addyess addyess left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Solid work. Dropping this dep will hopefully remove the circular dependency

@RonnyPfannschmidt RonnyPfannschmidt merged commit 7e867ad into pypa:main Sep 22, 2023
@@ -17,15 +16,32 @@
from ._config import Configuration, ParseFunction


log = _log.log.getChild("entrypoints")
from importlib.metadata import EntryPoint as EntryPoint
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this not be removed? It's outside the version condition.

Copy link
Contributor

@QuLogic QuLogic Sep 22, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, never mind me, I see it's available in Python 3.8 already, and I misread it as the plural.

@@ -15,10 +15,12 @@
".py": """\
# file generated by setuptools_scm
# don't change, don't track in version control
from __future__ import annotations
TYPE_CHECKING = False
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks weird. Doesn't this effectively always disable all type checking for this file?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Type checkers pretend such variables are true

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, this is not normal way to do this. Normally you import typing and check typing.TYPE_CHECKING. It is normally never set by user.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is a trick specifically for the type checkers

they use the variable name as indication, that way one does not have to do a runtime import

as importing typing can be expensive , its deemed that the version file ought not to impose that cost

so this really is just a dirty trick to avoid runtime imports in type check able files

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you sure this really works? Have you tested type checkers fail here if you provide wrong input? https://docs.python.org/3/library/typing.html#typing.TYPE_CHECKING says this is specifically a constant in typing module. Mypy documentation agrees https://mypy.readthedocs.io/en/stable/runtime_troubles.html#import-cycles

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The unit test is there specifically to check this

If necessary ill add a test with type assertions

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

Successfully merging this pull request may close these issues.

pip 23.0.1 and anyio==4.0.0 break installation with --upgrade --no-binary :all: options
4 participants