-
-
Notifications
You must be signed in to change notification settings - Fork 29.9k
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
Consider moving importlib.abc.InspectLoader.source_to_code() to importlib.abc.Loader #65355
Comments
importlib.abc.InspectLoader.source_to_code exists on InspectLoader because InspectLoader.get_code() uses it. But there is technically no reason to leave it there and not simply move it up to importlib.abc.Loader(). There is also no reason to not make it a staticmethod so that one can use it without worrying about abstractmethod overrides. |
source_to_code() seems like a good fit on InspectLoader to me. Is there |
The inspiration was that I realized there was no technical reason to have it on InspectLoader. Past that there was my thinking of trying to come up with a source_to_module() method on importlib.abc.Loader which would do the right thing with create_module() and init_module_attrs() such that replicating imp.load_module() would be something like:: loader = importlib.machinery.SourceLoader # or something
with open('file.py') as file:
module = loader.source_to_module(file.read(), location='file.py') |
Now that I've thought about it a little more, I'm more open to the idea. Source is definitely a universal concept in Python, as is code. So source_to_code() makes some sense on a most-base type like Loader. On the other hand, source isn't necessarily associated with all loaders. I guess my initial gut reaction was that it seemed out of place API-wise. On InspectLoader it's presence is tied to get_code(), so it makes more sense. |
New changeset 9bd844792b32 by Brett Cannon in branch 'default': |
I decided to make it a static method instead of relocating it. |
Making Given the ABC registration, it seems that Should we make |
@carl Feel free to open new issues for whatever you need. :) |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: