-
Notifications
You must be signed in to change notification settings - Fork 768
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
Metaclass custom or: Alternative syntax for unions requires Python 3.10 or newer #542
Comments
|
Scratch that, I missed that this is a third party django extension. |
If you just use a regular metaclass, not the "six" version, does it work? class BasePermission(object, metaclass=BasePermissionMetaclass):
... That decorator behavior isn't likely to fit in the type system. |
@jakebailey Yup, I can confirm that rewriting to:
does remove the error reported by Pylance. Sorry, but what does this mean in the context of this issue, can it be fixed here? Or somewhere else? |
The behavior of that |
@Zajozor Does this fix work for you, avoiding this |
If you want to stick with the |
Hi, thanks a lot for your time. @jakebailey It's a third party library (Django Rest Framework), so no, it does not really work for me to rewrite it because of this. One last question though, if I have two classes and use I would maybe expect the error message to tell me something like "MetaClass does not support It's definitely not a blocker, but i'd appreciate if you gave it a thought. |
Hello, Could you give me a heads-up on this topic? |
@NielsKorschinsky, I'm not able to repro the problem based on your description above. Could you please extract a small, minimal piece of code that exhibits the issue you're seeing? |
Of course, sure.
Not working:
Error message: My version:
|
I just did some more tests. It seems like the import: If i do not add this line in the code posted below, I'm reciving errors on every
|
Yes, I had assumed that you were using I see the error in both of your examples above when Is that inconsistent with what you're seeing? |
Incidentally, this has nothing to do with this bug report since this case doesn't involve custom metaclasses. If you still think there's a problem here, please open a new bug report so we can track it separately. |
Your screenshots show the exact same behavior as it is within my code. |
OK, good to hear. No need to delete your comments. Others may find them useful. Python 3.10 is under development. Pre-release (alpha) versions are available. We're just trying to stay ahead of the curve and implement new type-related functionality in preparation for the eventual release of 3.10. |
Closing old issue. Please reopen if necessary |
This was originally reported in #513 , however it ended up as being closed due to fixing a different problem related to type hints. As requested by @erictraut I'm reopening it here.
Environment data
Expected behaviour
Pylance should find out that the
|
operator is supported for the classes.Actual behaviour
Pylance reports the use of the
|
operator as invalid usage of alternative union syntax with python <3.10.Logs
No relevant logs
Additional information
We are using the Django Rest Framework and defining custom permission classes for a view:
Both permission classes which contain the
|
between them inherit from this classFurther related code can be found at https://github.com/encode/django-rest-framework/blob/master/rest_framework/permissions.py#L97 and near that.
And the
BasePermissionMetaclass
inherits fromOperationHolderMixin
which supports the__or__
operation.Please let me know if further information is required.
The text was updated successfully, but these errors were encountered: