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 TypeVar, Generic, ClassVar, Self | |
T = TypeVar("T", bound="BaseModel") | |
class BaseModel: | |
_meta: "ClassVar[Meta[Self]]" | |
class Meta(Generic[T]): | |
def __init__(self, model: type[T]) -> None: | |
self.model = model |
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 TypeVar, Generic, ClassVar, Self | |
# Define a generic type variable | |
T = TypeVar("T", bound="BaseModel") | |
class BaseModel: | |
"""A base model with a generic type parameter.""" | |
_meta: "ClassVar[Meta[Self]]" | |
class Meta(Generic[T]): |
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 enum import Enum | |
from typing import Type | |
menu_msg : str = \ | |
""" | |
Please select a valid size (1-3): | |
1. Small | |
2. Medium | |
3. Large |
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 enum import Enum | |
from typing import Type | |
menu_msg : str = \ | |
""" | |
Please select a valid size (1-3): | |
1. Small | |
2. Medium | |
3. Large |
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 TypedDict, Mapping | |
class FooType(TypedDict): | |
a: int | |
b: str | |
def foo(value: Mapping[str, int | str]): | |
print(value) | |
x = { |
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 TypedDict, Mapping | |
class FooType(TypedDict): | |
a: int | |
b: str | |
def foo(value: Mapping[str, int | str]): | |
print(value) | |
x = { |
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 collections.abc import Callable | |
from enum import Enum | |
from typing import Generic, Protocol, TypeVar, Type, overload | |
T = TypeVar("T", covariant=True) | |
class A(Generic[T]): | |
pass |
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 psycopg as pg | |
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
# mypy: allow-any-expr=False | |
class A(tuple[int, int]): ... | |
print(A()[:]) |
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
# mypy: allow-any-expr=False | |
class A(tuple[int, int]): ... | |
print(A()[:]) |
NewerOlder