Skip to content

Add GenericMeta (so that classes can be Generic when they already hav… - #703

Merged
gvanrossum merged 3 commits into
python:masterfrom
edx:add-generic-meta
Dec 2, 2016
Merged

gvanrossum merged 3 commits into
python:masterfrom
edx:add-generic-meta

Conversation

@cpennington

Copy link
Copy Markdown
Contributor

…e a metaclass)

@cpennington

Copy link
Copy Markdown
Contributor Author

I just tried this change locally, and it isn't working as advertised yet. Closing for now, until I can get it into a working state.

@gvanrossum

Copy link
Copy Markdown
Member

There's also the issue that GenericMeta isn't part of the documented API of the typing module. It's not in __all__ and it's not in the documentation (nor in PEP 484) and I'm pretty sure zero thought was given to how 3rd party code could or should subclass it.

@cpennington

Copy link
Copy Markdown
Contributor Author

Even if the only thing that was public was that there was a class of that name, that would be enough to safely typecheck the inheritance from the metaclass, which would allow a class to be typed as Generic while still using its own metaclass as well.

@gvanrossum

gvanrossum commented Nov 29, 2016 via email

Copy link
Copy Markdown
Member

@cpennington

Copy link
Copy Markdown
Contributor Author

https://github.com/cpennington/XBlock/blob/static-typing/xblock/mixins.py#L333-L358 is the particular chunk of code that I was trying to make this work for. (This repo is also the one that was prompting me to make descriptor typing work correctly).

@gvanrossum

Copy link
Copy Markdown
Member

OK, I think I see what you're after. I think we may have to document what you can/cannot do in a class derived from GenericMeta.

Does the code in this PR actually make this work for you, or do you need additional mypy changes as well?

@cpennington

Copy link
Copy Markdown
Contributor Author

It's broken right at the moment. I'll update once I've gotten it to work (my plan is to include as minimal a set of things in the stubs as I need to get that code working).

@cpennington

Copy link
Copy Markdown
Contributor Author

Ok, this is now sufficient for the code I referenced above.

@gvanrossum

gvanrossum commented Dec 2, 2016 via email

Copy link
Copy Markdown
Member

@cpennington

Copy link
Copy Markdown
Contributor Author

Oops, should be fixed now.

@gvanrossum

Copy link
Copy Markdown
Member

Thanks, this looks pretty harmless (and certainly minimal :-). I will merge it, even though I have lingering doubts about what should happen with the keyword args to __new__. I've got a feeling that your code that subclasses GenericMeta (https://github.com/cpennington/XBlock/blob/static-typing/xblock/mixins.py#L333-L358) would run into some kind of problem when get_type_hints() is called on something using one of those, since that ends up calling _eval_type(), which ends up calling self.__class__ (where self is a generic class, i.e. an instance of GenericMeta, so self.__class__ is GenericMeta or a subclass thereof) with all kinds of extra args. I guess you don't use that.

@gvanrossum
gvanrossum merged commit 5ba7abc into python:master Dec 2, 2016
@cpennington
cpennington deleted the add-generic-meta branch December 2, 2016 20:12
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