This file contains hidden or 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 * | |
class Foo: | |
class_var: ClassVar[str] = "somestr" | |
def bar(self) -> str: | |
return self.class_var | |
This file contains hidden or 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 List, Set | |
class Wizard: | |
def __init__(self, name, expert, spells): | |
self.name = name | |
self.spells = spells | |
self.expert = expert | |
def average_spell_power(self): | |
return sum(self.spells) / len(self.spells) |
This file contains hidden or 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
type Pair[T] = tuple[T, T] | |
class Foo[P: Pair]: | |
def __init__(self, pair: P) -> None: | |
self.pair: P = pair | |
foo = Foo((1, "a")) | |
reveal_type(foo) # Foo[tuple[int, str]] ❌ | |
reveal_type(foo.pair) # tuple[int, str] ❌ |
This file contains hidden or 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
type Pair[T] = tuple[T, T] | |
class Foo[P: Pair]: | |
def __init__(self, pair: P) -> None: | |
self.pair: P = pair | |
foo = Foo((1, "a")) | |
reveal_type(foo) # Foo[tuple[int, str]] ❌ | |
reveal_type(foo.pair) # tuple[int, str] ❌ |
This file contains hidden or 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 TYPE_CHECKING | |
class A: | |
if not TYPE_CHECKING: | |
def __eq__(self, other: object) -> bool: | |
return False | |
A() == 1 |
This file contains hidden or 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
class A: | |
def __eq__(self, other: object) -> bool: | |
return False | |
A() == 1 | |
class B: pass | |
B() == 1 |
This file contains hidden or 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
class A: | |
def __eq__(self, other: object) -> bool: | |
return False | |
A() == 1 | |
class B: pass | |
B() == 1 |
This file contains hidden or 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
class A: | |
def __eq__(self, other: object) -> bool: | |
return False | |
A() == 1 |
This file contains hidden or 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 enum | |
import functools | |
import typing as t | |
class Color(enum.Enum): | |
RED = enum.auto() | |
@enum.nonmember | |
@functools.cache |
This file contains hidden or 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 Never, Self, overload | |
from warnings import deprecated | |
class MyClass: | |
def __init__(self: Self, x: int): | |
self.x = x | |
@overload | |
def __eq__(self, other: Self) -> bool: ... | |
NewerOlder