Skip to content

Reason for re.Match.group and re.Match.__getitem__ returning AnyStr | Any? #9465

Closed as not planned
@willfrey

Description

@willfrey

Is there a reason why the return annotation is AnyStr | Any instead of AnyStr | None in the snippets below?

typeshed/stdlib/re.pyi

Lines 72 to 77 in b1cb9c8

@overload
def group(self, __group: Literal[0] = ...) -> AnyStr: ...
@overload
def group(self, __group: str | int) -> AnyStr | Any: ...
@overload
def group(self, __group1: str | int, __group2: str | int, *groups: str | int) -> tuple[AnyStr | Any, ...]: ...

typeshed/stdlib/re.pyi

Lines 96 to 99 in b1cb9c8

@overload
def __getitem__(self, __key: Literal[0]) -> AnyStr: ...
@overload
def __getitem__(self, __key: int | str) -> AnyStr | Any: ...

If not, I'd like to submit a PR to change the return type hints accordingly.

Thank you!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions