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
Using a custom implementation for live reloading python code.
Description
Upgrading to setuptools>=70.0.0 I notice some failure in some simple use case due to the change of signature of the _EditableFinder used when a python module is installed in editable mode.
The change was introduced in this commit-19b63d1b and it alter the standard signature of the classmethod find_spec of a PathFinder.
In fixing the PathEntryFinder a change of the signature was introduced for argument _path and _target:
# From deffind_spec(fullname, path=None, target=None):
...
# To deffind_spec(cls, fullname: str, _path=None, _target=None):
...
Expected behavior
The _EditableFinder use the standard PathFinder naming convention for the methods's arguments.
How to Reproduce
Install any local python package in editable mode
Add the import of the recently installed package in the script's main
Run the script.
importsysimportfunctoolsdefinstall():
"""Install the patch to the sys.meta_path finders classes. This function replaces the `find_spec` function of each finder to ensure that any ModuleSpecs will use the `ModuleLoader` internally` """# Wrapper for find_specdefwrap_find_spec(find_spec):
@functools.wraps(find_spec)defwrapper(fullname, path, target=None):
spec=find_spec(fullname=fullname, path=path, target=target)
ifspecisnotNone:
# Do other stuff with the spec.loaderpassreturnspecreturnwrapper# Wrap system meta path findersforfinderinsys.meta_path:
# Override the functions we care aboutifhasattr(finder, "find_spec"):
setattr(finder, "find_spec", wrap_find_spec(finder.find_spec))
if__name__=="__main__":
install()
# Now import a python package installed in editable mode# import <editable-package>
Output
❯ python main.pyTraceback (most recent call last): File "/Users/mtreglia/setuptools-repro/main.py", line 34, in <module> import sandbox File "<frozen importlib._bootstrap>", line 1027, in _find_and_load File "<frozen importlib._bootstrap>", line 1002, in _find_and_load_unlocked File "<frozen importlib._bootstrap>", line 945, in _find_spec File "/Users/mtreglia/setuptools-repro/main.py", line 15, in wrapper spec = find_spec(fullname=fullname, path=path, target=target)TypeError: _EditableFinder.find_spec() got an unexpected keyword argument 'path'
The text was updated successfully, but these errors were encountered:
Hi @mtreglia-gpsw, my currently understanding is that Python docs nudge towards what we would call nowadays "protocol".
When discussing protocols in this context, the feedback that I once got was the following:
Protocols should usually have positional-only parameters, because otherwise implementations need to use the exact same parameter names. Use positional-or-keyword parameters only if consumers of the protocol pass keyword arguments.
So I think it makes more sense for "client code" to use positional-style calling conventions. Otherwise it will always be at the risk of exceptions. For example, in the code snippet that you gave, I think that at least relying on fullname= keyword style invocation is problematic.
That said, I am happy to consider a PR (we probably need to add the specific type: ignore annotation though). Would you like to submit one?
Uh oh!
There was an error while loading. Please reload this page.
setuptools version
setuptools>=70.0.0
Python version
Python3.10
OS
macOS
Additional environment information
Using a custom implementation for live reloading python code.
Description
Upgrading to
setuptools>=70.0.0
I notice some failure in some simple use case due to the change of signature of the_EditableFinder
used when a python module is installed in editable mode.The change was introduced in this commit-19b63d1b and it alter the standard signature of the classmethod find_spec of a
PathFinder
.In fixing the
PathEntryFinder
a change of the signature was introduced for argument_path
and_target
:Expected behavior
The
_EditableFinder
use the standardPathFinder
naming convention for the methods's arguments.How to Reproduce
main
Output
The text was updated successfully, but these errors were encountered: