-
-
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
Mistaken 'Name already defined' for decorated function #4117
Comments
This check is trying to find true duplicates like def f(): pass
def f(): pass but I agree when there are different definitions in two branches it's annoying. However, what would you want to happen if the two definitions are not compatible? |
The check actually handles a function with the same name being defined in different branches of a conditional - the problem only occurs if the second definition is decorated. I've added a comment above to reflect this. The full motivating example is this code. So "all that's needed" for compatible functions is handling decorated functions in the existing heuristic. There are reasonable use-cases for differently-typed functions defined in branches (eg Py2/3 compatible str/bytes handling), so the 'correct enough' behavior would be to take the union of these function types where more than one could be in scope. Currently, Mypy reveals the type of |
I guess we should keep this bug for the case where at least one of the branches is decorated (assuming the decorator doesn't change the type). I'm not sure what should be done (regardless decorators) if the types don't match -- in some cases you'd like this to infer the intersection of the two types, but if the duplication is accidental that could cause really confusing error messages for code elsewhere that's calling the function. In any case I believe we already have some issues about that. (If you feel the need to further discuss this, please search for relevant issues first and cross-link if you find one.) |
I have a problem with this error popping up on redefining decorated functions for |
@berislavlopac there is some discussion of what to do with the case of |
Seems to be fixed as of 0.761 😄 |
enable categorical profiling for spark string types reduce toPandas calls in describe_numeric_spark by aggregating calls black reformatting add mypy test requirement to fix known mypy bug in python/mypy#4117 upgrade mypy to hopefully fix _ errors fix linting with isort and black add spark correlations for pearson and spearman, and new method in spark dataframes to get numeric spark types optimise kendall, spearman and pearson for spark add categorical support in dataframe wrapper finish cramer's computation using pure spark update pytest stuff start spark testing fix spark tests, fix correlations handling 1 column or less
While working on HypothesisWorks/hypothesis#858, I've found that decorated functions are mis-detected as already defined in another branch, if either both functions or only the second are decorated. I've simplified this to the following example:
This bug is still present as of mypy 0.610
The text was updated successfully, but these errors were encountered: