APIs related to importlib.abc.PathEntryFinder
should use protocol instead
#11541
Labels
stubs: improvement
Improve/refactor existing annotations, other stubs issues
Although
importlib.abc.PathEntryFinder
is defined as an abstract class in the standard library,path entry finders
are intentionally loosely defined in the Python docs (and originated PEPs), so that the only thing that needs to be implemented is one method (find_spec
). This matches the functioning of a protocol.The reason why the abstract class is defined is probably informational (for documentation purposes) + extra code re-use internally in the stdlib. This situation is similar to
importlib.abc.MetaPathFinder
, and otherimportlib.abc
classes (like loaders).This affects
typeshed/stdlib/sys/__init__.pyi
Line 54 in af84d2f
For example, I would expect the following snippet to type check with no problems:
But instead I am having an error:
https://mypy-play.net/?mypy=latest&python=3.12&gist=dfd3a0dcf277afc43cf59c8eb07afc5b
The text was updated successfully, but these errors were encountered: