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
Feature
I would expect that default valued argument inherit the value type. Hence the following code would fail because "f" is called with a str instead of an int, and because it internally assigns to an str.
Personally I would implement this by default, but having a flag to enable it could also be an option.
That's the way it works in other languages (eg. typescript)
default values are typically literals (since mutable objects are not good defaults), and it's rare that providing eg. an int default, an str would be also accepted. So, the most common case will require shorter code.
If the developer wants to set a default value but wants to allow other types, it feels more natural to have to explicitly add ": Any"
Mypy already reports "Incompatible types in assignment" for the code below, which is quite conceptually similar.
class A:
a=5
A.a = "asd"
Tools like pycharm automatically inherit the type from the default value. See snapshot
thanks!
The text was updated successfully, but these errors were encountered:
Feature
I would expect that default valued argument inherit the value type. Hence the following code would fail because "f" is called with a str instead of an int, and because it internally assigns to an str.
Personally I would implement this by default, but having a flag to enable it could also be an option.
Pitch
My rationale for adding the check:
thanks!
The text was updated successfully, but these errors were encountered: