Skip to content

[WIP] Uniform handling of metaclasses #2365

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

Closed
wants to merge 7 commits into from
Closed

Conversation

elazarg
Copy link
Contributor

@elazarg elazarg commented Oct 28, 2016

In order to fix #2305, I think we need a better handling of metaclasses: store the type of the metaclass in TypeInfo, and use it when possible, instead of builtins.type.

I assume metaclasses inherit from type; I don't yet follow the documentation.

This PR requires changes to typeshed.

@elazarg
Copy link
Contributor Author

elazarg commented Oct 28, 2016

For some reason (circularity?) the tests do not recognize abc.ABCMeta, but do recognize from abc import ABCMeta

@elazarg
Copy link
Contributor Author

elazarg commented Oct 28, 2016

How do I test changes to typeshed?

@JukkaL
Copy link
Collaborator

JukkaL commented Oct 28, 2016

Typeshed has a travis build that does some minimal consistency checks. I think that there's a script you can also run locally, but I haven't tried that. You can also run the mypy test suite locally against your typeshed changes. pythoneval.test in the mypy repo has tests that run against the full stubs, so if your stub changes are tightly coupled to changes to mypy internals, you can add some tests there. Note that they are much slower than most other tests, so we generally avoid adding tests there unless we really want to test interactions with real typeshed stubs.

More generally, you can write some dummy code that uses your changed stubs and manually try to verify that type checking and running a program seem compatible.

If your typeshed and mypy changes happen to depend on each other for a clean build, you'll probably want to coordinate them with a mypy core dev, as one of the builds may have to be red at least momentarily until both changes have been merged.

@elazarg
Copy link
Contributor Author

elazarg commented Oct 28, 2016

Thanks

@@ -118,3 +118,17 @@ takes_int(SomeExtIntEnum.x)
def takes_some_ext_int_enum(s: SomeExtIntEnum):
pass
takes_some_ext_int_enum(SomeExtIntEnum.x)

[case testEnumIter]
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can you also add a normal unit test that defines a metaclass and uses it? It may be better to first merge the code change + the unit test (that doesn't depend on typeshed), and land the typeshed change and the pythoneval test separately. This way the commit history is a little cleaner and there's less coupling to typeshed changes.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

There seem to be other tests relying on typeshed

FAILURE  #3 check file runtests.py

typeshed/stdlib/3/types.pyi:111: note: In module imported here,
typeshed/stdlib/3/sys.pyi:10: note: ... from here,
runtests.py:9: note: ... from here:
typeshed/stdlib/3/_importlib_modulespec.pyi:36: error: Name 'abc.ABCMeta' is not defined
typeshed/stdlib/3/_importlib_modulespec.pyi:36: error: Invalid metaclass 'abc.ABCMeta'

@JukkaL
Copy link
Collaborator

JukkaL commented Oct 28, 2016

(I didn't do a detailed review, just mentioned that it may better to split this PR.)

@gvanrossum
Copy link
Member

gvanrossum commented Oct 28, 2016

I think that there's a script you can also run locally, but I haven't tried that.

Here's the way I do it.

  • I have a virtualenv with Python 3 enabled
  • My typeshed repo is a subdirectory of my mypy repo
  • cd into the typeshed repo
  • git pull or edit or whatever you want to test
  • PYTHONPATH=.. python3 tests/mypy_test.py

This runs 5 sets of tests:

$ PYTHONPATH=.. python3 tests/mypy_test.py
running mypy --python-version 3.5 --strict-optional # with 342 files
running mypy --python-version 3.4 --strict-optional # with 342 files
running mypy --python-version 3.3 --strict-optional # with 327 files
running mypy --python-version 3.2 --strict-optional # with 326 files
running mypy --python-version 2.7 --strict-optional # with 380 files

You can limit it to a single Python version using -p2 or -p3.5.

(UPDATE: I've now added this information to the typeshed README.md.)

@elazarg
Copy link
Contributor Author

elazarg commented Oct 30, 2016

I think I will wait for syncing typeshed and reopen another one.

@elazarg elazarg closed this Oct 30, 2016
@elazarg elazarg mentioned this pull request Nov 22, 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.

Support iteration on enums
3 participants