Skip to content

Direct import for metaclass ABCMeta #640

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

Merged
merged 2 commits into from
Oct 30, 2016
Merged

Conversation

elazarg
Copy link
Contributor

@elazarg elazarg commented Oct 30, 2016

Added from abc import ABCMeta in importlib.

This change is needed for mypy/#2365.

@gvanrossum
Copy link
Member

That is very strange. Why is that needed? If you don't know, I suggest you research it further before answering. :-)

@elazarg
Copy link
Contributor Author

elazarg commented Oct 30, 2016

I can't say I know for sure, but I have a strong suspicion. I believe this is due to the priority given to from imports inside mypy. If so, this PR is an implementation detail of mypy leaking into typeshed, but I think the reason behind it - the fact that the name is immediately needed, IIUC - is relevant to metaclasses.

Perhaps this can be changed from inside mypy; if so, I can put this PR on hold. But the solutions I came up with were ugly hacks.

@@ -5,7 +5,7 @@
# - Loader in importlib.abc
# - ModuleSpec in importlib.machinery (3.4 and later only)

import abc
from abc import ABCMeta
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this case I'd say add abstractmethod too and get rid of the previous line (import abc), and modify all @abc.abstractmethod to @abstractmethod.

@gvanrossum
Copy link
Member

OK, I think that is actually reasonable. A tweak just in mypy might be to detect that a class or other object in an imported module is used in a position where it is immediately needed (e.g. base class, metaclass, decorator) but that feels fairly hard since all those calculations have to be done in semanal.FirstPass which doesn't have a lot of understanding yet.

@gvanrossum gvanrossum merged commit 1d47c6f into python:master Oct 30, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants