Skip to content

Add metaclasses for string.Template and dataclasses.InitVar #8852

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Oct 5, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions stdlib/dataclasses.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import types
from builtins import type as Type # alias to avoid name clashes with fields named "type"
from collections.abc import Callable, Iterable, Mapping
from typing import Any, Generic, Protocol, TypeVar, overload
from typing_extensions import Literal
from typing_extensions import Literal, TypeAlias

if sys.version_info >= (3, 9):
from types import GenericAlias
Expand Down Expand Up @@ -217,7 +217,14 @@ def is_dataclass(obj: Any) -> bool: ...

class FrozenInstanceError(AttributeError): ...

class InitVar(Generic[_T]):
if sys.version_info >= (3, 9):
_InitVarMeta: TypeAlias = type
else:
class _InitVarMeta(type):
# Not used, instead `InitVar.__class_getitem__` is called.
def __getitem__(self, params: Any) -> InitVar[Any]: ...

class InitVar(Generic[_T], metaclass=_InitVarMeta):
type: Type[_T]
def __init__(self, type: Type[_T]) -> None: ...
if sys.version_info >= (3, 9):
Expand Down
11 changes: 9 additions & 2 deletions stdlib/string.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ from _typeshed import StrOrLiteralStr
from collections.abc import Iterable, Mapping, Sequence
from re import Pattern, RegexFlag
from typing import Any, ClassVar, overload
from typing_extensions import LiteralString
from typing_extensions import LiteralString, TypeAlias

__all__ = [
"ascii_letters",
Expand Down Expand Up @@ -32,7 +32,14 @@ whitespace: LiteralString

def capwords(s: StrOrLiteralStr, sep: StrOrLiteralStr | None = ...) -> StrOrLiteralStr: ...

class Template:
if sys.version_info >= (3, 9):
_TemplateMetaclass: TypeAlias = type
else:
class _TemplateMetaclass(type):
pattern: ClassVar[str]
def __init__(cls, name: str, bases: tuple[type, ...], dct: dict[str, Any]) -> None: ...

class Template(metaclass=_TemplateMetaclass):
template: str
delimiter: ClassVar[str]
idpattern: ClassVar[str]
Expand Down