You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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
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?
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?
No description provided.
The text was updated successfully, but these errors were encountered: