-
Notifications
You must be signed in to change notification settings - Fork 2
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
Non-Protocol Intersection #12
Comments
The implementation is explicitly only targeting protocols, as it's a relatively simple problem to solve. This plugin will only ever support intersection of protocols (hence the name ;)). General type intersection is a much more involving problem. There's a discussion on the topic in the python/typing repository python/typing#213 and there's actually a PEP in the works to make this happen https://github.com/CarliJoy/intersection_examples I remember reading excellent examples as to why it's not so simple somewhere in that thread, but I don't have them at hand anymore unfortunately, you'll have to dig if you're interested. |
Do you know if a MyPy plugin exists/could be written to allow a normal class to be promoted to a protocol so that it could be used with your intersection? I have been experimenting with your code and setting is_protocol=True on all the classes passed to the intersection allows your plugin to work with non-protocol classes however this effects the class outside of the intersection. |
Sorry, I don't know.
I would advise against modifying this plugin in such way (making it do things it's not supposed to do), unless you're familiar with internals of mypy itself. The goal of a type checker ultimately is to make you trust the code more. If you can't trust the type-checker, it misses the point. |
Is there a reason why this can't be used with non-protocol classes?
This seems like the solution I have been looking for but I need it to work with non-protocol classes.
I hope that one day Python will have a native intersection type but until then this could be a useful stopgap.
The text was updated successfully, but these errors were encountered: