From 1de56d3f11ccf850c3987cacd636d40d92c79d3a Mon Sep 17 00:00:00 2001 From: Stephen Morton Date: Tue, 19 Dec 2023 16:09:23 -0800 Subject: [PATCH 1/3] move re.error into re.pyi implementation is in sre_constants / re._constants, but it sets it's __module__ to re --- stdlib/re.pyi | 9 ++++++++- stdlib/sre_constants.pyi | 9 +-------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/stdlib/re.pyi b/stdlib/re.pyi index ec532ca3cffe..14c072bd89e0 100644 --- a/stdlib/re.pyi +++ b/stdlib/re.pyi @@ -3,7 +3,6 @@ import sre_compile import sys from _typeshed import ReadableBuffer from collections.abc import Callable, Iterator, Mapping -from sre_constants import error as error from typing import Any, AnyStr, Generic, TypeVar, overload from typing_extensions import Literal, TypeAlias, final @@ -47,6 +46,14 @@ if sys.version_info >= (3, 11): _T = TypeVar("_T") +class error(Exception): + msg: str + pattern: str | bytes | None + pos: int | None + lineno: int + colno: int + def __init__(self, msg: str, pattern: str | bytes | None = None, pos: int | None = None) -> None: ... + @final class Match(Generic[AnyStr]): @property diff --git a/stdlib/sre_constants.pyi b/stdlib/sre_constants.pyi index d522372c438c..5ad3d78ba6a3 100644 --- a/stdlib/sre_constants.pyi +++ b/stdlib/sre_constants.pyi @@ -1,4 +1,5 @@ import sys +from re import error as error from typing import Any from typing_extensions import Self @@ -6,14 +7,6 @@ MAXGROUPS: int MAGIC: int -class error(Exception): - msg: str - pattern: str | bytes | None - pos: int | None - lineno: int - colno: int - def __init__(self, msg: str, pattern: str | bytes | None = None, pos: int | None = None) -> None: ... - class _NamedIntConstant(int): name: Any def __new__(cls, value: int, name: str) -> Self: ... From a989bb7a0035f5a67a07cfc98e5fef86de6133c0 Mon Sep 17 00:00:00 2001 From: Stephen Morton Date: Wed, 20 Dec 2023 10:47:57 -0800 Subject: [PATCH 2/3] add explanation --- stdlib/re.pyi | 2 ++ 1 file changed, 2 insertions(+) diff --git a/stdlib/re.pyi b/stdlib/re.pyi index 14c072bd89e0..adaac5de6562 100644 --- a/stdlib/re.pyi +++ b/stdlib/re.pyi @@ -46,6 +46,8 @@ if sys.version_info >= (3, 11): _T = TypeVar("_T") +# The implementation defines this in re._constants (version_info >= 3, 11) or +# sre_constants. Typeshed has it here because it's __module__ attribute is set to "re". class error(Exception): msg: str pattern: str | bytes | None From 7c4fe1eaa7eeec4942dddd0c382144a3ae9dd09d Mon Sep 17 00:00:00 2001 From: Jelle Zijlstra Date: Tue, 1 Oct 2024 18:35:12 -0700 Subject: [PATCH 3/3] Update re.pyi --- stdlib/re.pyi | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/stdlib/re.pyi b/stdlib/re.pyi index e8383a741e25..ac297b7d4567 100644 --- a/stdlib/re.pyi +++ b/stdlib/re.pyi @@ -4,8 +4,8 @@ import sre_constants import sys from _typeshed import ReadableBuffer from collections.abc import Callable, Iterator, Mapping -from typing import Any, AnyStr, Generic, TypeVar, overload -from typing_extensions import Literal, TypeAlias, final +from typing import Any, AnyStr, Generic, Literal, TypeVar, final, overload +from typing_extensions import TypeAlias if sys.version_info >= (3, 9): from types import GenericAlias