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
def assert_equals(expected: Union[str, bytes], actual: Union[str, bytes]) -> bool:
if type(expected) is str:
expected = bytes(expected, "utf-8")
if type(actual) is str:
actual = bytes(actual, "utf-8")
if expected == actual:
return True
else:
logger.error(f"Expected: {expected!r}, Actual: {actual!r}.")
return False
def assert_in(look: Union[str, bytes], where: Union[str, bytes]) -> bool:
if type(look) is str:
look = bytes(look, "utf-8")
if type(where) is str:
where = bytes(where, "utf-8")
if look in where:
return True
else:
logger.error(f"Looking for {look!r}, but contents are {where!r}.")
return False
The error is:
line 3: error: Argument 1 to "bytes" has incompatible type "Union[str, bytes]"; expected "str"
line 5: error: Argument 1 to "bytes" has incompatible type "Union[str, bytes]"; expected "str"
line 16: error: Argument 1 to "bytes" has incompatible type "Union[str, bytes]"; expected "str"
line 18: error: Argument 1 to "bytes" has incompatible type "Union[str, bytes]"; expected "str"
line 20: error: Unsupported operand types for in ("Union[str, bytes]" and "Union[str, bytes]")
So even though we convert the variables to a specific type, MyPy still thinks that it is of type Union.
The text was updated successfully, but these errors were encountered:
MyPy complains with the following code:
The error is:
So even though we convert the variables to a specific type, MyPy still thinks that it is of type Union.
The text was updated successfully, but these errors were encountered: