Skip to content

Instantly share code, notes, and snippets.

@cipherboy
Last active October 18, 2019 00:15
Show Gist options
  • Save cipherboy/31afa9551cb38e78ae8d63b0ad379c3d to your computer and use it in GitHub Desktop.
Save cipherboy/31afa9551cb38e78ae8d63b0ad379c3d to your computer and use it in GitHub Desktop.
MyPy Wat
cmsh/var.py:222: error: Argument 1 to "v_not" has incompatible type "Union[bool, Variable]"; expected "Variable"
cmsh/var.py:276: error: Argument 1 to "v_not" has incompatible type "Union[bool, Variable]"; expected "Variable"
cmsh/var.py:318: error: Argument 1 to "v_not" has incompatible type "Union[bool, Variable]"; expected "Variable"
def b_nand(left: Union[bool, Variable], right: Union[bool, Variable]) -> Union[bool, Variable]:
"""
Computes the binary NAND between left and right operands.
Args:
left (bool or Variable): left operand.
right (bool or Variable): right operand.
Returns:
bool or Variable: the result of the operation.
"""
if isinstance(left, bool) and isinstance(right, bool):
return not (left and right)
if isinstance(left, bool):
if not left:
return True
return v_not(right)
if isinstance(right, bool):
if not right:
return True
return v_not(left)
return v_nand(left, right)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment