You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I do not understand mypy's behavior on the below code. It reports an error when a certain function call is part of the return statement, but not when the same function call is separated from the return statement by an intermediate variable.
It might be a bug, but also a valid behavior which is just unclear to me.
fromtypingimportOptional, Type, TypeVarclassCustom:
pass# when the bound is removed, mypy reports no errorT=TypeVar('T', bound=Custom)
defa(cls: Type[T]) ->Optional[T]:
returncls()
defb(cls: Type[T]) ->Optional[T]:
# the return statement triggers the following mypy error:# Value of type variable "T" of "a" cannot be "Optional[T]"returna(cls)
defc(cls: Type[T]) ->Optional[T]:
tmp=a(cls)
# when an intermediate variable is used, no error is reportedreturntmp
The actual behavior is that the error Value of type variable "T" of "a" cannot be "Optional[T]" is reported on the return statement in function b, but not in function c.
I would expect that either the same error was reported both in function b and c or that no error was reported at all. The current behavior seems inconsistent to me. Moreover, I do not understand the root cause of the reported problem.
Q: Do you see the same issue after installing mypy from Git master?
A: Yes, the behavior is the same with mypy 0.620+dev-bc0b551d8df2baadc44f0c3b0b801fcc12119658.
Q: What are the mypy flags you are using? (For example --strict-optional)
A: no flags and no configuration files, simply running mypy script.py
The text was updated successfully, but these errors were encountered:
This is yet another duplicate of #4872. The error for b is a false positive, and using a temporary variable is the current workaround. Thanks for reporting!
I do not understand mypy's behavior on the below code. It reports an error when a certain function call is part of the return statement, but not when the same function call is separated from the return statement by an intermediate variable.
It might be a bug, but also a valid behavior which is just unclear to me.
The actual behavior is that the error
Value of type variable "T" of "a" cannot be "Optional[T]"
is reported on the return statement in functionb
, but not in functionc
.I would expect that either the same error was reported both in function
b
andc
or that no error was reported at all. The current behavior seems inconsistent to me. Moreover, I do not understand the root cause of the reported problem.Q: Do you see the same issue after installing mypy from Git master?
A: Yes, the behavior is the same with
mypy 0.620+dev-bc0b551d8df2baadc44f0c3b0b801fcc12119658
.Q: What are the mypy flags you are using? (For example --strict-optional)
A: no flags and no configuration files, simply running
mypy script.py
The text was updated successfully, but these errors were encountered: