This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from typing import Literal, override | |
class Foo: | |
@override | |
def __eq__(self, value: object, /) -> bool: | |
return True | |
def fun(a: Foo | Literal["a"]) -> None: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from typing import Literal, override | |
class Foo: | |
@override | |
def __eq__(self, value: object, /) -> bool: | |
return True | |
def fun(a: Foo | Literal["a"]) -> None: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from typing import Iterator | |
def fib(n: int) -> Iterator[int]: | |
a, b = 0, 1 | |
while a < n: | |
yield a | |
a, b = b, a + b | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from typing import NamedTuple | |
class Record(NamedTuple): | |
id: int | |
name: str | |
age: int | |
reveal_type(Record.name) # str |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from __future__ import annotations | |
from dataclasses import dataclass | |
import os | |
from n2t.core.vm_translator.writer import Writer | |
from n2t.core.vm_translator.vm_parser import INSTRUCTIONS, VmParser | |
@dataclass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import typing | |
class NDArray: | |
shape: tuple | |
def __setitem__(self, idx: NDArray, v: object) -> None: ... | |
def random(x: object) -> NDArray: return NDArray() | |
Image = typing.NewType('Image', NDArray) | |
Mask = typing.NewType('Mask', NDArray) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from typing import NewType, TYPE_CHECKING | |
class Weight(int): | |
if TYPE_CHECKING: | |
def __iadd__(self, x: object): ... | |
x = Weight(10) | |
y = Weight(2) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from typing import NewType | |
Weight = NewType("Weight", int) | |
x = Weight(10) | |
y = Weight(2) | |
# This is what I want to do | |
x += y |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from typing import NewType | |
Weight = NewType("Weight", int) | |
x = Weight(10) | |
y = Weight(2) | |
# This is what I want to do | |
x += y |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from typing import NewType | |
Weight = NewType("Weight", int) | |
x = Weight(10) | |
y = Weight(2) | |
x += y | |
x = Weight(x + y) |
NewerOlder