Skip to content

Improve email.headerregistry.HeaderRegistry definition #8516

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 6 commits into from
Aug 10, 2022
Merged
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
14 changes: 12 additions & 2 deletions stdlib/email/headerregistry.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ from email._header_value_parser import (
)
from email.errors import MessageDefect
from email.policy import Policy
from typing import Any, ClassVar
from typing import Any, ClassVar, Protocol
from typing_extensions import Literal

class BaseHeader(str):
Expand Down Expand Up @@ -141,9 +141,19 @@ if sys.version_info >= (3, 8):
@staticmethod
def value_parser(value: str) -> MessageID: ...

class _HeaderParser(Protocol):
max_count: ClassVar[Literal[1] | None]
@staticmethod
def value_parser(value: str) -> TokenList: ...
@classmethod
def parse(cls, value: str, kwds: dict[str, Any]) -> None: ...

class HeaderRegistry:
registry: dict[str, type[_HeaderParser]]
base_class: type[BaseHeader]
default_class: type[_HeaderParser]
def __init__(
self, base_class: type[BaseHeader] = ..., default_class: type[BaseHeader] = ..., use_default_map: bool = ...
self, base_class: type[BaseHeader] = ..., default_class: type[_HeaderParser] = ..., use_default_map: bool = ...
) -> None: ...
def map_to_type(self, name: str, cls: type[BaseHeader]) -> None: ...
def __getitem__(self, name: str) -> type[BaseHeader]: ...
Expand Down