From c1f02485f15c15c0d45e8389e116553899a8be61 Mon Sep 17 00:00:00 2001 From: Kevin Rose Date: Mon, 4 Oct 2021 17:48:49 -0500 Subject: [PATCH 1/3] Add the rest of string.Template's class attributes --- stdlib/string.pyi | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/stdlib/string.pyi b/stdlib/string.pyi index ceed38f00931..9c6b779cb6c0 100644 --- a/stdlib/string.pyi +++ b/stdlib/string.pyi @@ -1,4 +1,5 @@ -from typing import Any, Iterable, Mapping, Sequence, Tuple +# from re import RegexFlag # Importing from regex breaks the Markdown stubtest +from typing import Any, Iterable, Mapping, Pattern, Sequence, Tuple ascii_letters: str ascii_lowercase: str @@ -14,6 +15,11 @@ def capwords(s: str, sep: str | None = ...) -> str: ... class Template: template: str + delimiter: str + idpattern: str + braceidpattern: str | None + flags: Any # RegexFlag + pattern: Pattern[str] def __init__(self, template: str) -> None: ... def substitute(self, __mapping: Mapping[str, object] = ..., **kwds: object) -> str: ... def safe_substitute(self, __mapping: Mapping[str, object] = ..., **kwds: object) -> str: ... From e622c6871ef98184643e91dc5bc4464480e6a016 Mon Sep 17 00:00:00 2001 From: Kevin Rose Date: Tue, 5 Oct 2021 08:17:44 -0500 Subject: [PATCH 2/3] Import from re --- stdlib/string.pyi | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/stdlib/string.pyi b/stdlib/string.pyi index 9c6b779cb6c0..dde199d3b1d3 100644 --- a/stdlib/string.pyi +++ b/stdlib/string.pyi @@ -1,5 +1,5 @@ -# from re import RegexFlag # Importing from regex breaks the Markdown stubtest -from typing import Any, Iterable, Mapping, Pattern, Sequence, Tuple +from re import Pattern, RegexFlag # Importing from regex breaks the Markdown stubtest +from typing import Any, Iterable, Mapping, Sequence, Tuple ascii_letters: str ascii_lowercase: str @@ -18,7 +18,7 @@ class Template: delimiter: str idpattern: str braceidpattern: str | None - flags: Any # RegexFlag + flags: RegexFlag pattern: Pattern[str] def __init__(self, template: str) -> None: ... def substitute(self, __mapping: Mapping[str, object] = ..., **kwds: object) -> str: ... From 8e1803695c4b09dd446b556a0ede660fadb9136a Mon Sep 17 00:00:00 2001 From: Kevin Rose Date: Tue, 5 Oct 2021 08:20:29 -0500 Subject: [PATCH 3/3] Guard import of Pattern on sys.version --- stdlib/string.pyi | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/stdlib/string.pyi b/stdlib/string.pyi index dde199d3b1d3..321b2647fbb2 100644 --- a/stdlib/string.pyi +++ b/stdlib/string.pyi @@ -1,6 +1,12 @@ -from re import Pattern, RegexFlag # Importing from regex breaks the Markdown stubtest +import sys +from re import RegexFlag from typing import Any, Iterable, Mapping, Sequence, Tuple +if sys.version_info >= (3, 8): + from re import Pattern +else: + from typing import Pattern + ascii_letters: str ascii_lowercase: str ascii_uppercase: str