Replies: 1 comment 2 replies
-
going to try this: def caller_two(
thing: Thing[_T],
) -> Union[_T, int]:
return cast(Union[_T, int], function_two(thing)) that seems to convince it |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
This one happens on Mypy but not on Pyright. In the example below,
function_two()
would like to return either an instance of_T
or an integer status code. however trying to call uponfunction_two()
, mypy expands out_T
to include the type of the status code as well. It doesnt do this in the identical case where status code would be the None constant. Seems kind of buggy but at the same time I can sort of guess how it is making this mistake, so not sure how to proceed other than returning Any forfunction_two()
or otherwise degrading the quality of typing. Making _T a more specific TypeVar fixes, but the use case is against any arbitrary user-defined class. I would, if possible, have it exclude integers, but I dont know how to make a TypeVar that excludes certain types only.output:
Beta Was this translation helpful? Give feedback.
All reactions