-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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
Unsupported operand types using += with floats initialized to 0 (not 0.0) #1193
Comments
I agree that we should do something about this. The question is, what
should the scope of this type adjustment be? What if I have a foo that
initializes a class variable foo to 0 and then a method executes
`self.foo += 0.5` ? What if that method is in a subclass?
The fix we have in place for variables initialized to empty lists only
works for locals -- but it is often insufficient, so I think we need a
more general architecture for these types of type adjustments.
|
We could probably tweak partial types to work for the original example, but as Guido pointed out, it would not work in general. However, it might be good enough. I'd like to see more real-world examples before deciding what to do with this. Note that you can also add an annotation (though changing the initializer is usually easier):
|
Yep makes sense; for a data point I had to do this 6 times in zulip.git.
On Fri, Jan 29, 2016 at 12:02 PM, Jukka Lehtosalo notifications@github.com
|
@timabbott Could you give more information about the 6 cases in zulip.git -- or were they all similar to |
5/6 are like that and the other is like that except x is in a dict. |
mypy complains with:
/home/tabbott/foo.py:4: error: Unsupported operand types for + ("int" and "float")
with the following code:While one can work around this by initializing to 0.0, it seems worth thinking about if mypy should accept this.
The text was updated successfully, but these errors were encountered: