-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
mypy returns invalid type: "bytes"
in classes that define a bytes
instance attribute
#3687
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
Comments
Thanks for reporting this! I reproduced the issue on 0.511, what's more concerning is that this is a crash on master!
As expected, renaming |
The crash should be not hard to fix. |
Let's wait until the release since this also happens on 0.511. |
Ah so it's an error on 0.511 but a crash on master? Hmm I still want to move forward with the release, but if the fix is simple we may release 0.521 later this week. |
There are probably a few more candidates for 0.521...
…On Mon, Jul 10, 2017 at 2:02 PM, Jukka Lehtosalo ***@***.***> wrote:
Ah so it's an error on 0.511 but a crash on master? Hmm I still want to
move forward with the release, but if the fix is simple we may release
0.521 later this week.
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#3687 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/ACwrMnSDeVIoFyLMlHa435jsra4ctQ9tks5sMpFxgaJpZM4OTT-K>
.
--
--Guido van Rossum (python.org/~guido)
|
Here's a simpler example that generates the crash: class C:
def __init__(self) -> None:
self.int = ''
def f(self, f: int) -> None:
f.x Since the original issue hasn't been reported previously, this may be a fairly rare thing. The original error also was tricky to |
OK, here is a (simple) fix #3700. |
Fixes #3687 (fixes both the crash and the underlying name resolution issue). The fix is quite simple, I also noticed that normalized flag for symbol table nodes was not serialized, so I added this too.
Thanks for handling this so quickly and efficiently! I gave a talk on type annotations at EuroPython 2017 and was happy to point out how great the support of the MyPy team is. If you're interested, here are the slides: https://www.slideshare.net/japh44/type-annotations-in-python-whats-whys-and-wows I also looked at the usage of type hints in the wild (analyzing the top 1000 Python repos on Github), which might be interesting to you: https://github.com/adewes/type-annotations-in-the-wild Thanks anyway, really looking forward to using mypy regularly in my work. |
Thanks! I am impressed with your talk. Thanks for spreading the word for us! |
Fixes #3687 (fixes both the crash and the underlying name resolution issue). The fix is quite simple, I also noticed that normalized flag for symbol table nodes was not serialized, so I added this too.
When trying to add type annotations to a project (https://github.com/DCSO/flor),
mypy
would complain thatbytes
was not a valid type, which was quite puzzling to say the least. After some head scratching and searching in the issue log I was able to reproduce the problem with a simple module (Python 3.5.2+ with mypy 0.511):Running
mypy example.py
returns the following error messages:When renaming
self.bytes
toself._bytes
, no issues are reported. It seems that mypy mistakesself.bytes
for a class variable, although it is an instance variable and not visible at the declaration time of functionbar
.The text was updated successfully, but these errors were encountered: