When I run mypy --python-version 3.6 on the following code:
fromtypingimportAnyStrdeff(x: AnyStr) ->bytes:
returnx.encode("ascii") ifisinstance(x, str) elsexI get:
test.py:3: error: "bytes" has no attribute "encode"; maybe "decode"?
But as far as I can tell, this is backwards! x.encode("ascii") is only called when isinstance(x, str), not in the else case (where x is a bytes object).
This is with the latest mypy==0.530
When I run
mypy --python-version 3.6on the following code:I get:
But as far as I can tell, this is backwards!
x.encode("ascii")is only called whenisinstance(x, str), not in theelsecase (where x is abytesobject).This is with the latest
mypy==0.530