-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Consider --allow-redefinition
for mypy
#3832
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
ref #3767 |
I have mixed feelings about this. Sometimes it's nice to redefine variables (I often encounter this when a function accepts an arg with a union type but we then convert it to a single type and want the rest of the code to use this "narrowed" type). But other times a redefinition is inadvertent and mypy flagging it can actually detect bugs (sometimes bugs like this only surface when refactoring). It looks like |
I'm going through the numpy stuff and there are a non-zero number of places where redefinitions are used, especially when constructing arrays: arr: List[float]
for thing in iterator:
arr.append(complicated_function(thing))
arr: np.ndarray = np.asarray(arr) |
Discussion in Cirq sync:
From mypy: |
This is a tough call, because there are pros and cons for both options (add, or don't add). Based on the fact that (a) the default of not adding |
See python/mypy#1174 for full context, but there are common idioms where you may want to re-use a variable name
Mypy currently complains. They added a flag: python/mypy#6197 which may or may not become the default at some point. I say we add this to our mypy configuration.
The text was updated successfully, but these errors were encountered: