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

Make importlib_metadata._meta.SimplePath public #494

Closed
matthewhughes934 opened this issue Jul 10, 2024 · 4 comments
Closed

Make importlib_metadata._meta.SimplePath public #494

matthewhughes934 opened this issue Jul 10, 2024 · 4 comments

Comments

@matthewhughes934
Copy link

I see this class is documented https://importlib-metadata.readthedocs.io/en/latest/api.html#importlib_metadata._meta.SimplePath but the fact it is under the ._meta package, which looks private at a glance, makes me wonder: is is supported for me to access this, is its API as stable as any other part of the package? Additionally (if the answer is yes): could this class just be re-exported by importlib_metadata to avoid this need for access to ._meta?

My use case is: I have a class that sub-classes Distribution and need to annotate the return value for locate_file which should be one of these SimplePaths, and asking here because this appears to be the origin of the class, with it being added upstream from here: python/cpython@667294d

@jaraco
Copy link
Member

jaraco commented Jul 23, 2024

Great question. I'm fairly sure I made it private so that it wouldn't be used as an API. For type checking, however, it probably should be exposed. SimplePath was added in #315.

@FFY00 Do you have any concerns with exporting SimplePath in importlib_metadata (__init__.py)?

@jaraco jaraco changed the title Question about accessing importlib_metadata._meta.SimplePath Make importlib_metadata._meta.SimplePath public Jul 23, 2024
@matthewhughes934
Copy link
Author

🤔 actually, since SimplePath is a protocol, exposing it feels unnecessary: why can't my code just return a concrete type that implements it

@FFY00
Copy link
Member

FFY00 commented Jul 24, 2024

@FFY00 Do you have any concerns with exporting SimplePath in importlib_metadata (__init__.py)?

I don't, I think it should be exposed.

🤔 actually, since SimplePath is a protocol, exposing it feels unnecessary: why can't my code just return a concrete type that implements it

That might be fine in your particular use-case, but if you want to annotate a public API that consumes SimplePath types, it makes sense to have it exposed.

@jaraco
Copy link
Member

jaraco commented Jul 24, 2024

Oh, I see it's already exposed; it's just not listed in __all__ (making it explicitly, intentionally exposed); I'll do that.

@jaraco jaraco closed this as completed in d18ae21 Jul 24, 2024
matthewhughes934 added a commit to matthewhughes934/py-unused-deps that referenced this issue Sep 28, 2024
Remove type ignore only needed for Python 3.7 or less, since we've
dropped support for Python 3.7.

Fix error on return type for stubbed out function, the error was:

    tests/utils.py:40: error: Return type "PathLike[str]" of "locate_file" incompatible with return type "Path" in supertype "Distribution"  [override]

This `SimplePath` isn't exported (but should be in the future[1]) but
it's just a protocol implementing some bits of `pathlib.Path`[2] so drop
that in instead.

[1] python/importlib_metadata#494
[2] https://github.com/python/cpython/blob/69a4063ca516360b5eb96f5432ad9f9dfc32a72e/Lib/importlib/metadata/_meta.py#L47
matthewhughes934 added a commit to matthewhughes934/py-unused-deps that referenced this issue Sep 28, 2024
Remove type ignore only needed for Python 3.7 or less, since we've
dropped support for Python 3.7.

Fix error on return type for stubbed out function, the error was:

    tests/utils.py:40: error: Return type "PathLike[str]" of "locate_file" incompatible with return type "Path" in supertype "Distribution"  [override]

This `SimplePath` isn't exported (but should be in the future[1]) but
it's just a protocol implementing some bits of `pathlib.Path`[2] so drop
that in instead.

[1] python/importlib_metadata#494
[2] https://github.com/python/cpython/blob/69a4063ca516360b5eb96f5432ad9f9dfc32a72e/Lib/importlib/metadata/_meta.py#L47
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

3 participants