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

Do we need to define importlib.abc.PathEntryFinder.find_spec() #103999

Open
Tracked by #97850
warsaw opened this issue Apr 29, 2023 · 2 comments
Open
Tracked by #97850

Do we need to define importlib.abc.PathEntryFinder.find_spec() #103999

warsaw opened this issue Apr 29, 2023 · 2 comments
Labels
stdlib Python modules in the Lib dir

Comments

@warsaw
Copy link
Member

warsaw commented Apr 29, 2023

No description provided.

@warsaw warsaw changed the title importlib.abs.PathEntryFinder has this comment: "We don't define find_spec() here since that would break hasattr checks we do to support backward compatibility." Do we need to define find_spec() in this ABC? Do we need to define importlib.abc.PathEntryFinder.find_spec() Apr 29, 2023
@warsaw
Copy link
Member Author

warsaw commented Apr 29, 2023

importlib.abc.PathEntryFinder has this comment: "We don't define find_spec() here since that would break hasattr checks we do to support backward compatibility." Do we need to define find_spec() in this ABC?

@iritkatriel iritkatriel added the stdlib Python modules in the Lib dir label Nov 28, 2023
@tungol
Copy link
Contributor

tungol commented Dec 16, 2024

importlib.abc.MetaPathFinder has the same comment. Just in case someone looks at this issue later and is confused: PathEntryFinder doesn't have the comment anymore, it was removed in #98059, but it was there before that.

One problem: importlib.metadata.DistributionFinder inherits from MetaPathFinder. That's another abstract class, which in turn is a base class for the concrete importlib.metadata.MetadataPathFinder. MetadataPathFinder does not implement find_spec, and either it or DistributionFinder would need to if find_spec is added to MetaPathFinder as an abstract method. The documented failure state for find_spec is just to return None, so maybe that's fine. Or find_spec can be added to MetaPathFinder with a default implementation that just returns None.

All the documentation says these ABCs have these as abstract methods; it'd be good to have that be true. I think probably the right thing for MetaPathFinder is to have the abstract method, and then an implementation on DistributionFinder that just returns None.

One final wrinkle: All the implementations of MetaPathFinder in the standard library have find_spec as a classmethod. We don't document it as a classmethod on MetaPathFinder, and looking at the first page of github search results, I didn't see any third-party users who implemented find_spec as a classmethod. Should it be a classmethod on MetaPathFinder?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stdlib Python modules in the Lib dir
Projects
None yet
Development

No branches or pull requests

3 participants