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
{{ message }}
Repository navigation
Incompatible return value type with TypeVar #10003
fromtypingimportTypeVarimportunittestAnyT=TypeVar("AnyT")
defstrip_if_str(value: AnyT) ->AnyT:
ifisinstance(value, str):
returnvalue.strip()
returnvalueclassTestStripIfStr(unittest.TestCase):
deftest_str(self) ->None:
self.assertEqual(strip_if_str(" a b c "), "a b c")
deftest_notstr(self) ->None:
self.assertEqual(strip_if_str(3), 3)
if__name__=="__main__":
unittest.main()
$ python -m mypy --show-error-context --show-error-codes .test_typevar_identity.py: note: In function "strip_if_str":test_typevar_identity.py:9: error: Incompatible return value type (got "str", expected "AnyT") [return-value]Found 1 error in 1 file (checked 1 source file)
Activity
giladreti commentedon Feb 1, 2021
Same here.
This code generates
Incompatible return value type (got "int", expected "T"):aucampia commentedon Jan 22, 2022
Also having this problem:
I think this is similar to:
aucampia commentedon Jan 22, 2022
Possible other issues that is related to this one:
fzimmermann89 commentedon Nov 10, 2024
Are there any plans to fix this? Or is there a good work around?
Narrow type variable bounds in binder (python#19183)