Skip to content

Instantly share code, notes, and snippets.

@mypy-play
Created May 8, 2024 19:55
Show Gist options
  • Save mypy-play/6f8c8cd5e9d0cb43b92270894b7305e8 to your computer and use it in GitHub Desktop.
Save mypy-play/6f8c8cd5e9d0cb43b92270894b7305e8 to your computer and use it in GitHub Desktop.
Shared via mypy Playground
from typing import NewType, TYPE_CHECKING
class Weight(int):
if TYPE_CHECKING:
def __iadd__(self, x: object): ...
x = Weight(10)
y = Weight(2)
# This is what I want to do
x += y
# This is what I have to do
x = Weight(x + y)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment