-
Notifications
You must be signed in to change notification settings - Fork 767
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
bytes
is not being expanded to Union[bytes|bytearray|memoryview]
#692
Comments
Thanks for the bug report. I hadn't ever heard of this either. I've added the support, and it will be in the next release. |
Is this something I'm struggling with myself? def parse_str(i: int, data: ???):
# do some
if (data[i+1] <= 0): # taking element as an int here
# dome some
result = codecs.decode(data[x:y], 'encoding') If I use type I'm completely confused here - is this a Pylance-strict issue or I dont understand something about python type-checking? |
Unless I'm mistaken, the effect of the fix will be that any of those three types will be compatible with |
So in other words it is/was pylance-specific issue? Since I dont have much experience working in python env I wasnt sure if vanilla mypy is under-reporting (since it has zero issues whatsoever with anything I put in there) or pylance being wrong. |
Even though there is no actual class relationship between bytes, bytearray and memoryview (i.e. none of them are subclasses of each other), The version of Pylance that was published last week doesn't properly handle the type promotions for |
Hmm, okay, sure. But I dont think that explains why explicitly stated type def parse_str(i: int, data: Union[bytes, bytearray, memoryview]) -> str:
# do some
if (data[i+1] <= 0): # taking element as an int here
# dome some
result = codecs.decode(data[x:y], 'encoding')
^--- type error here Why Pylance reports a type error here in this case? |
|
This is definitely not the same problem as the bug that was reported in this issue. If you think there's a separate bug, please open another issue and provide a minimal code sample that exhibits the problem. |
This issue has been fixed in version 2020.12.1, which we've just released. You can find the changelog here: https://github.com/microsoft/pylance-release/blob/master/CHANGELOG.md#2020121-9-december-2020 |
Environment data
Expected behaviour
bytes
is able to be used as a shorthand fortyping.Union[bytes|bytearray|memoryview]
in argument types, so this code should not have a typing error:Actual behaviour
The second argument to
os.write()
is marked with this message:Logs
Not sure I enabled this correctly, there was only one mention of Pylance.
Code Snippet / Additional information
The shorthand is documented. I came across this when looking at the history of python/typeshed#3109, where one of the review comments said that expanding the typing stub for
os.write()
to include types other thanbytes
wasn't necessary.The text was updated successfully, but these errors were encountered: