From 8cafdb180fedc0eb71c36db164a9c3d69d48de4c Mon Sep 17 00:00:00 2001 From: Stacks-Mamba Date: Wed, 23 Sep 2020 22:29:26 +0100 Subject: [PATCH 01/33] Finish BasicAuthHandler missing stubs --- stdlib/3/urllib/request.pyi | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/stdlib/3/urllib/request.pyi b/stdlib/3/urllib/request.pyi index 1e529067b75f..c4d28ac42037 100644 --- a/stdlib/3/urllib/request.pyi +++ b/stdlib/3/urllib/request.pyi @@ -2,6 +2,7 @@ import os import ssl import sys from email.message import Message +from re import Pattern from http.client import HTTPMessage, HTTPResponse, _HTTPConnectionProtocol from http.cookiejar import CookieJar from typing import IO, Any, Callable, ClassVar, Dict, List, Mapping, NoReturn, Optional, Sequence, Tuple, TypeVar, Union, overload @@ -122,8 +123,14 @@ class HTTPPasswordMgrWithPriorAuth(HTTPPasswordMgrWithDefaultRealm): def is_authenticated(self, authuri: str) -> bool: ... class AbstractBasicAuthHandler: + rx: ClassVar[Pattern] # undocumented def __init__(self, password_mgr: Optional[HTTPPasswordMgr] = ...) -> None: ... def http_error_auth_reqed(self, authreq: str, host: str, req: Request, headers: Mapping[str, str]) -> None: ... + def http_request(self, req: Request) -> Request: ... # undocumented + def http_response(self, req: Request, response: HTTPResponse) -> HTTPResponse: ... # undocumented + def https_request(self, req: Request) -> Request: ... # undocumented + def https_response(self, req: Request, response: HTTPResponse) -> HTTPResponse: ... # undocumented + def retry_http_basic_auth(self, host: str, req: Request, realm: str) -> Optional[ _UrlopenRet]: ... # undocumented class HTTPBasicAuthHandler(AbstractBasicAuthHandler, BaseHandler): def http_error_401( From 5a5cf8fcceda8231d285939e536a55b0159c798b Mon Sep 17 00:00:00 2001 From: Stacks-Mamba Date: Wed, 23 Sep 2020 23:00:04 +0100 Subject: [PATCH 02/33] Fix style stuff --- run_tests.sh | 8 ++++++++ stdlib/3/urllib/request.pyi | 18 ++++++++---------- 2 files changed, 16 insertions(+), 10 deletions(-) create mode 100644 run_tests.sh diff --git a/run_tests.sh b/run_tests.sh new file mode 100644 index 000000000000..f77d6e9be65f --- /dev/null +++ b/run_tests.sh @@ -0,0 +1,8 @@ +!# /bin/bash + + +python3 tests/mypy_test.py +python3 tests/pytype_test.py +python3 tests/mypy_selftest.py +python3 tests/stubtest_test.py +flake8 diff --git a/stdlib/3/urllib/request.pyi b/stdlib/3/urllib/request.pyi index c4d28ac42037..628212af7d96 100644 --- a/stdlib/3/urllib/request.pyi +++ b/stdlib/3/urllib/request.pyi @@ -2,10 +2,9 @@ import os import ssl import sys from email.message import Message -from re import Pattern from http.client import HTTPMessage, HTTPResponse, _HTTPConnectionProtocol from http.cookiejar import CookieJar -from typing import IO, Any, Callable, ClassVar, Dict, List, Mapping, NoReturn, Optional, Sequence, Tuple, TypeVar, Union, overload +from typing import IO, Any, Callable, ClassVar, Dict, List, Mapping, NoReturn, Optional, Sequence, Tuple, TypeVar, Union, overload, Pattern from urllib.response import addinfourl _T = TypeVar("_T") @@ -93,8 +92,7 @@ class HTTPRedirectHandler(BaseHandler): self, req: Request, fp: IO[str], code: int, msg: int, headers: Mapping[str, str] ) -> Optional[_UrlopenRet]: ... def http_error_303( - self, req: Request, fp: IO[str], code: int, msg: int, headers: Mapping[str, str] - ) -> Optional[_UrlopenRet]: ... + self, req: Request, fp: IO[str], code: int, msg: int, headers: Mapping[str, str]) -> Optional[_UrlopenRet]: ... def http_error_307( self, req: Request, fp: IO[str], code: int, msg: int, headers: Mapping[str, str] ) -> Optional[_UrlopenRet]: ... @@ -123,14 +121,14 @@ class HTTPPasswordMgrWithPriorAuth(HTTPPasswordMgrWithDefaultRealm): def is_authenticated(self, authuri: str) -> bool: ... class AbstractBasicAuthHandler: - rx: ClassVar[Pattern] # undocumented + rx: ClassVar[Pattern] # undocumented def __init__(self, password_mgr: Optional[HTTPPasswordMgr] = ...) -> None: ... def http_error_auth_reqed(self, authreq: str, host: str, req: Request, headers: Mapping[str, str]) -> None: ... - def http_request(self, req: Request) -> Request: ... # undocumented - def http_response(self, req: Request, response: HTTPResponse) -> HTTPResponse: ... # undocumented - def https_request(self, req: Request) -> Request: ... # undocumented - def https_response(self, req: Request, response: HTTPResponse) -> HTTPResponse: ... # undocumented - def retry_http_basic_auth(self, host: str, req: Request, realm: str) -> Optional[ _UrlopenRet]: ... # undocumented + def http_request(self, req: Request) -> Request: ... # undocumented + def http_response(self, req: Request, response: HTTPResponse) -> HTTPResponse: ... # undocumented + def https_request(self, req: Request) -> Request: ... # undocumented + def https_response(self, req: Request, response: HTTPResponse) -> HTTPResponse: ... # undocumented + def retry_http_basic_auth(self, host: str, req: Request, realm: str) -> Optional[_UrlopenRet]: ... # undocumented class HTTPBasicAuthHandler(AbstractBasicAuthHandler, BaseHandler): def http_error_401( From c4b9db987762196bd6b8814996f5b8e0e7a04b99 Mon Sep 17 00:00:00 2001 From: Stacks-Mamba Date: Wed, 23 Sep 2020 23:00:49 +0100 Subject: [PATCH 03/33] Remove bad file --- run_tests.sh | 8 -------- 1 file changed, 8 deletions(-) delete mode 100644 run_tests.sh diff --git a/run_tests.sh b/run_tests.sh deleted file mode 100644 index f77d6e9be65f..000000000000 --- a/run_tests.sh +++ /dev/null @@ -1,8 +0,0 @@ -!# /bin/bash - - -python3 tests/mypy_test.py -python3 tests/pytype_test.py -python3 tests/mypy_selftest.py -python3 tests/stubtest_test.py -flake8 From e6f627676e85f56f3e7739fa36ae8926628efcb5 Mon Sep 17 00:00:00 2001 From: Stacks-Mamba Date: Wed, 23 Sep 2020 23:02:05 +0100 Subject: [PATCH 04/33] tweak .gitignore --- .gitignore | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.gitignore b/.gitignore index a800141bd870..5d82516b3beb 100644 --- a/.gitignore +++ b/.gitignore @@ -66,3 +66,6 @@ analyze.py # Mypy cache .mypy_cache/ + +#A helper script +run_tests.sh From 4763b63cf8acb6ad74dc62f490b2bad3344914c2 Mon Sep 17 00:00:00 2001 From: Stacks-Mamba Date: Wed, 23 Sep 2020 23:53:14 +0100 Subject: [PATCH 05/33] Add missing methods to ftp handlers --- stdlib/3/urllib/request.pyi | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/stdlib/3/urllib/request.pyi b/stdlib/3/urllib/request.pyi index 628212af7d96..df131beda06d 100644 --- a/stdlib/3/urllib/request.pyi +++ b/stdlib/3/urllib/request.pyi @@ -183,12 +183,21 @@ class FileHandler(BaseHandler): class DataHandler(BaseHandler): def data_open(self, req: Request) -> addinfourl: ... +class ftpwrapper: # undocumented + def __init__( + self, user: str, passwd: str, host: str, port: int, dirs: str, timeout: Optional[float] = ..., persistent: bool = ... + ) -> None: ... + class FTPHandler(BaseHandler): def ftp_open(self, req: Request) -> addinfourl: ... + def connect_ftp(self, user: str, passwd: str, host: str, port: int, dirs: str, timeout: float) -> ftpwrapper: ... # undocumented class CacheFTPHandler(FTPHandler): def setTimeout(self, t: float) -> None: ... def setMaxConns(self, m: int) -> None: ... + def check_cache(self) -> None: ... # undocumented + def clear_cache(self) -> None: ... # undocumented + def connect_ftp(self, user: str, passwd: str, host: str, port: int, dirs: str, timeout: float) -> ftpwrapper: ... # undocumented class UnknownHandler(BaseHandler): def unknown_open(self, req: Request) -> NoReturn: ... From eb857cbe0a71f1515bd41b9cdeceb804567accf8 Mon Sep 17 00:00:00 2001 From: Stacks-Mamba Date: Thu, 24 Sep 2020 10:29:59 +0100 Subject: [PATCH 06/33] Add FancyURLopener methods --- stdlib/3/urllib/request.pyi | 43 ++++++++++++++++++++++++++++++++++++- 1 file changed, 42 insertions(+), 1 deletion(-) diff --git a/stdlib/3/urllib/request.pyi b/stdlib/3/urllib/request.pyi index df131beda06d..2e13707e76cc 100644 --- a/stdlib/3/urllib/request.pyi +++ b/stdlib/3/urllib/request.pyi @@ -183,7 +183,7 @@ class FileHandler(BaseHandler): class DataHandler(BaseHandler): def data_open(self, req: Request) -> addinfourl: ... -class ftpwrapper: # undocumented +class ftpwrapper: # undocumented def __init__( self, user: str, passwd: str, host: str, port: int, dirs: str, timeout: Optional[float] = ..., persistent: bool = ... ) -> None: ... @@ -239,3 +239,44 @@ class URLopener: class FancyURLopener(URLopener): def prompt_user_passwd(self, host: str, realm: str) -> Tuple[str, str]: ... + def get_user_passwd(self, host: str, realm: str, clear_cache: int = ...) -> Tuple[str, str]: ... # undocumented + def http_error_301( + self, url: str, fp: IO[str], errcode: int, errmsg: str, headers: Mapping[str, str], data: Optional[bytes] = ... + ) -> Optional[Union[_UrlopenRet, addinfourl]]: ... # undocumented + def http_error_302( + self, url: str, fp: IO[str], errcode: int, errmsg: str, headers: Mapping[str, str], data: Optional[bytes] = ... + ) -> Optional[Union[_UrlopenRet, addinfourl]]: ... # undocumented + def http_error_303( + self, url: str, fp: IO[str], errcode: int, errmsg: str, headers: Mapping[str, str], data: Optional[bytes] = ... + ) -> Optional[Union[_UrlopenRet, addinfourl]]: ... # undocumented + def http_error_307( + self, url: str, fp: IO[str], errcode: int, errmsg: str, headers: Mapping[str, str], data: Optional[bytes] = ... + ) -> Optional[Union[_UrlopenRet, addinfourl]]: ... # undocumented + def http_error_401( + self, url: str, + fp: IO[str], + errcode: int, + errmsg: str, + headers: Mapping[str, str], + data: Optional[bytes] = ..., + retry: bool = ... + ) -> Optional[_UrlopenRet]: ... # undocumented + def http_error_407( + self, url: str, + fp: IO[str], + errcode: int, + errmsg: str, + headers: Mapping[str, str], + data: Optional[bytes] = ..., + retry: bool = ... + ) -> Optional[_UrlopenRet]: ... # undocumented + def http_error_default( + self, url: str, fp: IO[str], errcode: int, errmsg: str, headers: Mapping[str, str] + ) -> addinfourl: ... # undocumented + def redirect_internal( + self, url: str, fp: IO[str], errcode: int, errmsg: str, headers: Mapping[str, str], data: Optional[bytes] + ) -> Optional[_UrlopenRet]: ... # undocumented + def retry_http_basic_auth(self, url: str, realm: str, data: Optional[bytes] = ...) -> Optional[_UrlopenRet]: ... # undocumented + def retry_https_basic_auth(self, url: str, realm: str, data: Optional[bytes] = ...) -> Optional[_UrlopenRet]: ... # undocumented + def retry_proxy_http_basic_auth(self, url: str, realm: str, data: Optional[bytes] = ...) -> Optional[_UrlopenRet]: ... # undocumented + def retry_proxy_https_basic_auth(self, url: str, realm: str, data: Optional[bytes] = ...) -> Optional[_UrlopenRet]: ... # undocumented From 8f9eb70d0dcd1061d5e10ece9516d45530fc0c7c Mon Sep 17 00:00:00 2001 From: Stacks-Mamba Date: Thu, 24 Sep 2020 11:27:07 +0100 Subject: [PATCH 07/33] Add FileHandler channel --- stdlib/3/urllib/request.pyi | 3 +++ 1 file changed, 3 insertions(+) diff --git a/stdlib/3/urllib/request.pyi b/stdlib/3/urllib/request.pyi index 2e13707e76cc..527754feea90 100644 --- a/stdlib/3/urllib/request.pyi +++ b/stdlib/3/urllib/request.pyi @@ -178,7 +178,10 @@ class HTTPSHandler(AbstractHTTPHandler): def https_request(self, request: Request) -> Request: ... # undocumented class FileHandler(BaseHandler): + names: ClassVar[Optional[Tuple[str, ...]]] def file_open(self, req: Request) -> addinfourl: ... + def get_names(self) -> Tuple[str, ...]: ... # undocumented + def open_local_file(self, req: Request) -> Optional[addinfourl]: ... # undocumented class DataHandler(BaseHandler): def data_open(self, req: Request) -> addinfourl: ... From 703e571551fbaef5dc207a65175e5a3c72867a69 Mon Sep 17 00:00:00 2001 From: Stacks-Mamba Date: Thu, 24 Sep 2020 11:53:09 +0100 Subject: [PATCH 08/33] Add HTTPCookieProcessor missing stubs --- stdlib/3/urllib/request.pyi | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/stdlib/3/urllib/request.pyi b/stdlib/3/urllib/request.pyi index 527754feea90..36f99a00d278 100644 --- a/stdlib/3/urllib/request.pyi +++ b/stdlib/3/urllib/request.pyi @@ -100,6 +100,10 @@ class HTTPRedirectHandler(BaseHandler): class HTTPCookieProcessor(BaseHandler): cookiejar: CookieJar def __init__(self, cookiejar: Optional[CookieJar] = ...) -> None: ... + def http_request(self, request: Request) -> Request: ... # undocumented + def http_response(self, request: Request, response: HTTPResponse) -> HTTPResponse: ... # undocumented + def https_request(self, request: Request) -> Request: ... # undocumented + def https_response(self, request: Request, response: HTTPResponse) -> HTTPResponse: ... # undocumented class ProxyHandler(BaseHandler): def __init__(self, proxies: Optional[Dict[str, str]] = ...) -> None: ... @@ -131,6 +135,7 @@ class AbstractBasicAuthHandler: def retry_http_basic_auth(self, host: str, req: Request, realm: str) -> Optional[_UrlopenRet]: ... # undocumented class HTTPBasicAuthHandler(AbstractBasicAuthHandler, BaseHandler): + auth_header: str # undocumented def http_error_401( self, req: Request, fp: IO[str], code: int, msg: int, headers: Mapping[str, str] ) -> Optional[_UrlopenRet]: ... @@ -178,7 +183,7 @@ class HTTPSHandler(AbstractHTTPHandler): def https_request(self, request: Request) -> Request: ... # undocumented class FileHandler(BaseHandler): - names: ClassVar[Optional[Tuple[str, ...]]] + names: ClassVar[Optional[Tuple[str, ...]]] # undocumented def file_open(self, req: Request) -> addinfourl: ... def get_names(self) -> Tuple[str, ...]: ... # undocumented def open_local_file(self, req: Request) -> Optional[addinfourl]: ... # undocumented From 358c5f377cbb0688086629d6d6e1aaddc4384cbf Mon Sep 17 00:00:00 2001 From: Stacks-Mamba Date: Thu, 24 Sep 2020 12:36:49 +0100 Subject: [PATCH 09/33] Update .gitignore --- .gitignore | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 5d82516b3beb..7501b764f920 100644 --- a/.gitignore +++ b/.gitignore @@ -67,5 +67,8 @@ analyze.py # Mypy cache .mypy_cache/ -#A helper script +#Files i messed with locally run_tests.sh +.travis.yml +tests/mypy_selftest.py + From c58349fc0d46b7562d24574eebe27a650ea6a1bb Mon Sep 17 00:00:00 2001 From: Stacks-Mamba Date: Thu, 24 Sep 2020 12:39:00 +0100 Subject: [PATCH 10/33] Modify .gitignore --- .gitignore | 2 -- 1 file changed, 2 deletions(-) diff --git a/.gitignore b/.gitignore index 7501b764f920..65c8b31adeb3 100644 --- a/.gitignore +++ b/.gitignore @@ -70,5 +70,3 @@ analyze.py #Files i messed with locally run_tests.sh .travis.yml -tests/mypy_selftest.py - From 59ae776260ef29ef91c74e75630d7b7aaef08c22 Mon Sep 17 00:00:00 2001 From: Stacks-Mamba Date: Thu, 24 Sep 2020 12:52:05 +0100 Subject: [PATCH 11/33] Add stubs 3 more objects --- stdlib/3/urllib/request.pyi | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/stdlib/3/urllib/request.pyi b/stdlib/3/urllib/request.pyi index 36f99a00d278..19fb33d47e5e 100644 --- a/stdlib/3/urllib/request.pyi +++ b/stdlib/3/urllib/request.pyi @@ -6,6 +6,7 @@ from http.client import HTTPMessage, HTTPResponse, _HTTPConnectionProtocol from http.cookiejar import CookieJar from typing import IO, Any, Callable, ClassVar, Dict, List, Mapping, NoReturn, Optional, Sequence, Tuple, TypeVar, Union, overload, Pattern from urllib.response import addinfourl +from urllib.error import HTTPError _T = TypeVar("_T") _UrlopenRet = Any @@ -79,7 +80,10 @@ class BaseHandler: def close(self) -> None: ... def http_error_nnn(self, req: Request, fp: IO[str], code: int, msg: int, headers: Mapping[str, str]) -> _UrlopenRet: ... -class HTTPDefaultErrorHandler(BaseHandler): ... +class HTTPDefaultErrorHandler(BaseHandler): + def http_error_default( + self, req: Request, fp: IO[str], code: int, msg: str, hdrs: Mapping[str, str] + ) -> HTTPError: ... # undocumented class HTTPRedirectHandler(BaseHandler): def redirect_request( @@ -135,7 +139,7 @@ class AbstractBasicAuthHandler: def retry_http_basic_auth(self, host: str, req: Request, realm: str) -> Optional[_UrlopenRet]: ... # undocumented class HTTPBasicAuthHandler(AbstractBasicAuthHandler, BaseHandler): - auth_header: str # undocumented + auth_header: ClassVar[str] # undocumented def http_error_401( self, req: Request, fp: IO[str], code: int, msg: int, headers: Mapping[str, str] ) -> Optional[_UrlopenRet]: ... @@ -156,6 +160,7 @@ class AbstractDigestAuthHandler: def get_entity_digest(self, data: Optional[bytes], chal: Mapping[str, str]) -> Optional[str]: ... class HTTPDigestAuthHandler(BaseHandler, AbstractDigestAuthHandler): + auth_header: ClassVar[str] # undocumented def http_error_401( self, req: Request, fp: IO[str], code: int, msg: int, headers: Mapping[str, str] ) -> Optional[_UrlopenRet]: ... From a57cdbf556b279cff17d39dd080ae14af0abc88d Mon Sep 17 00:00:00 2001 From: Stacks-Mamba Date: Thu, 24 Sep 2020 13:12:00 +0100 Subject: [PATCH 12/33] revert .gitignore --- .gitignore | 4 ---- 1 file changed, 4 deletions(-) diff --git a/.gitignore b/.gitignore index 65c8b31adeb3..a800141bd870 100644 --- a/.gitignore +++ b/.gitignore @@ -66,7 +66,3 @@ analyze.py # Mypy cache .mypy_cache/ - -#Files i messed with locally -run_tests.sh -.travis.yml From 27fbb2daa2fd3d80c154aa00eb47936ebf81a571 Mon Sep 17 00:00:00 2001 From: Stacks-Mamba Date: Thu, 24 Sep 2020 13:12:46 +0100 Subject: [PATCH 13/33] Add stubs for HTTPPasswordMgr --- stdlib/3/urllib/request.pyi | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/stdlib/3/urllib/request.pyi b/stdlib/3/urllib/request.pyi index 19fb33d47e5e..59cc0492ec18 100644 --- a/stdlib/3/urllib/request.pyi +++ b/stdlib/3/urllib/request.pyi @@ -116,6 +116,10 @@ class ProxyHandler(BaseHandler): class HTTPPasswordMgr: def add_password(self, realm: str, uri: Union[str, Sequence[str]], user: str, passwd: str) -> None: ... def find_user_password(self, realm: str, authuri: str) -> Tuple[Optional[str], Optional[str]]: ... + def is_suburi(self, base: str, test: str) -> bool: ... # undocumented + def reduce_uri( + self, uri: Union[str, Sequence[str]], default_port: bool = ... + ) -> Tuple[Union[str, Sequence[str]], str]: ... # undocumented class HTTPPasswordMgrWithDefaultRealm(HTTPPasswordMgr): def add_password(self, realm: Optional[str], uri: Union[str, Sequence[str]], user: str, passwd: str) -> None: ... From 78c9a1791d6fe879bbbde54db5629098cd527169 Mon Sep 17 00:00:00 2001 From: Stacks-Mamba Date: Thu, 24 Sep 2020 13:23:53 +0100 Subject: [PATCH 14/33] Add stubs for HTTPRedirectHandler --- stdlib/3/urllib/request.pyi | 3 +++ 1 file changed, 3 insertions(+) diff --git a/stdlib/3/urllib/request.pyi b/stdlib/3/urllib/request.pyi index 59cc0492ec18..80b09e9f5331 100644 --- a/stdlib/3/urllib/request.pyi +++ b/stdlib/3/urllib/request.pyi @@ -86,6 +86,9 @@ class HTTPDefaultErrorHandler(BaseHandler): ) -> HTTPError: ... # undocumented class HTTPRedirectHandler(BaseHandler): + max_redirections: ClassVar[int] # undocumented + max_repeats: ClassVar[int] # undocumented + inf_msg: ClassVar[str] # undocumented def redirect_request( self, req: Request, fp: IO[str], code: int, msg: str, headers: Mapping[str, str], newurl: str ) -> Optional[Request]: ... From dfee4d30e1262a408fc6975decfabf42a34a6039 Mon Sep 17 00:00:00 2001 From: Stacks-Mamba Date: Thu, 24 Sep 2020 13:36:54 +0100 Subject: [PATCH 15/33] tweak .travis.yml --- .travis.yml | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/.travis.yml b/.travis.yml index 853b49c002f6..af2c44a7c313 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,6 +4,22 @@ python: 3.8 jobs: include: + - name: "mypy-selftest" + python: 2.7 + install: + - pip install -r requirements-tests-py3.txt + script: + - ./tests/mypy_selftest.py --platform=linux + - name: "py3-tests" + python: 3.6 + install: + - pip install -r requirements-tests-py3.txt + script: + - ./tests/mypy_test.py --platform=linux + - ./tests/pytype_test.py + - ./tests/stubtest_test.py + - ./tests/check_consistent.py + - flake8 - name: "mypy (typed-ast)" python: 3.7 install: pip install -U git+git://github.com/python/mypy git+git://github.com/python/typed_ast From 37bd617e1901634b024d9055cb833af47dca82cc Mon Sep 17 00:00:00 2001 From: Stacks-Mamba Date: Thu, 24 Sep 2020 13:46:02 +0100 Subject: [PATCH 16/33] tweak self_test --- tests/mypy_selftest.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/mypy_selftest.py b/tests/mypy_selftest.py index fd7f23b105bb..01a539f82fed 100755 --- a/tests/mypy_selftest.py +++ b/tests/mypy_selftest.py @@ -11,7 +11,7 @@ if __name__ == '__main__': with tempfile.TemporaryDirectory() as tempdir: dirpath = Path(tempdir) - subprocess.run(['python2.7', '-m', 'pip', 'install', '--user', 'typing'], check=True) + subprocess.run(['python3', '-m', 'pip', 'install','typing'], check=True) subprocess.run(['git', 'clone', '--depth', '1', 'git://github.com/python/mypy', str(dirpath / 'mypy')], check=True) subprocess.run([sys.executable, '-m', 'pip', 'install', '-U', '-r', From 2c4513b024b5916cf9e5e7e966f3ac2386619d2c Mon Sep 17 00:00:00 2001 From: Stacks-Mamba Date: Thu, 24 Sep 2020 13:48:08 +0100 Subject: [PATCH 17/33] tweak .travis.yml --- .travis.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index af2c44a7c313..2e75f030baef 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,7 +5,7 @@ python: 3.8 jobs: include: - name: "mypy-selftest" - python: 2.7 + python: 3.6 install: - pip install -r requirements-tests-py3.txt script: @@ -15,7 +15,6 @@ jobs: install: - pip install -r requirements-tests-py3.txt script: - - ./tests/mypy_test.py --platform=linux - ./tests/pytype_test.py - ./tests/stubtest_test.py - ./tests/check_consistent.py From 233d0a417458ca44c646499e06f81ce7fcc067d4 Mon Sep 17 00:00:00 2001 From: Stacks-Mamba Date: Thu, 24 Sep 2020 13:55:07 +0100 Subject: [PATCH 18/33] Add stubs for OpenerDirector --- stdlib/3/urllib/request.pyi | 1 + tests/mypy_selftest.py | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/stdlib/3/urllib/request.pyi b/stdlib/3/urllib/request.pyi index 80b09e9f5331..62fc36a4aa71 100644 --- a/stdlib/3/urllib/request.pyi +++ b/stdlib/3/urllib/request.pyi @@ -72,6 +72,7 @@ class OpenerDirector: def add_handler(self, handler: BaseHandler) -> None: ... def open(self, fullurl: Union[str, Request], data: Optional[bytes] = ..., timeout: Optional[float] = ...) -> _UrlopenRet: ... def error(self, proto: str, *args: Any) -> _UrlopenRet: ... + def close(self) -> None: ... class BaseHandler: handler_order: ClassVar[int] diff --git a/tests/mypy_selftest.py b/tests/mypy_selftest.py index 01a539f82fed..56ea619fa884 100755 --- a/tests/mypy_selftest.py +++ b/tests/mypy_selftest.py @@ -11,7 +11,7 @@ if __name__ == '__main__': with tempfile.TemporaryDirectory() as tempdir: dirpath = Path(tempdir) - subprocess.run(['python3', '-m', 'pip', 'install','typing'], check=True) + subprocess.run(['python3', '-m', 'pip', 'install', 'typing'], check=True) subprocess.run(['git', 'clone', '--depth', '1', 'git://github.com/python/mypy', str(dirpath / 'mypy')], check=True) subprocess.run([sys.executable, '-m', 'pip', 'install', '-U', '-r', From 4e7e466c2ccba4d9d56ee465a25768273485dc32 Mon Sep 17 00:00:00 2001 From: Stacks-Mamba Date: Thu, 24 Sep 2020 14:08:23 +0100 Subject: [PATCH 19/33] Add stubs for ProxyHandlers --- stdlib/3/urllib/request.pyi | 3 +++ 1 file changed, 3 insertions(+) diff --git a/stdlib/3/urllib/request.pyi b/stdlib/3/urllib/request.pyi index 62fc36a4aa71..fbd04db9febb 100644 --- a/stdlib/3/urllib/request.pyi +++ b/stdlib/3/urllib/request.pyi @@ -115,6 +115,7 @@ class HTTPCookieProcessor(BaseHandler): class ProxyHandler(BaseHandler): def __init__(self, proxies: Optional[Dict[str, str]] = ...) -> None: ... + def proxy_open(self, req: Request, proxy: str, type: str) -> Optional[_UrlopenRet]: ... # undocumented # TODO add a method for every (common) proxy protocol class HTTPPasswordMgr: @@ -153,6 +154,7 @@ class HTTPBasicAuthHandler(AbstractBasicAuthHandler, BaseHandler): ) -> Optional[_UrlopenRet]: ... class ProxyBasicAuthHandler(AbstractBasicAuthHandler, BaseHandler): + auth_header: ClassVar[str] def http_error_407( self, req: Request, fp: IO[str], code: int, msg: int, headers: Mapping[str, str] ) -> Optional[_UrlopenRet]: ... @@ -174,6 +176,7 @@ class HTTPDigestAuthHandler(BaseHandler, AbstractDigestAuthHandler): ) -> Optional[_UrlopenRet]: ... class ProxyDigestAuthHandler(BaseHandler, AbstractDigestAuthHandler): + auth_header: ClassVar[str] # undocumented def http_error_407( self, req: Request, fp: IO[str], code: int, msg: int, headers: Mapping[str, str] ) -> Optional[_UrlopenRet]: ... From 54144e0414763ecf90d5ef5d0644c60984e01da0 Mon Sep 17 00:00:00 2001 From: Stacks-Mamba Date: Thu, 24 Sep 2020 14:14:35 +0100 Subject: [PATCH 20/33] Add Request stub --- stdlib/3/urllib/request.pyi | 1 + 1 file changed, 1 insertion(+) diff --git a/stdlib/3/urllib/request.pyi b/stdlib/3/urllib/request.pyi index fbd04db9febb..ef0de4869830 100644 --- a/stdlib/3/urllib/request.pyi +++ b/stdlib/3/urllib/request.pyi @@ -66,6 +66,7 @@ class Request: @overload def get_header(self, header_name: str, default: _T) -> Union[str, _T]: ... def header_items(self) -> List[Tuple[str, str]]: ... + def has_proxy(self) -> bool: ... class OpenerDirector: addheaders: List[Tuple[str, str]] From f57027e64e083e4b7fc4ab22dcc4784ce6b6ecad Mon Sep 17 00:00:00 2001 From: Stacks-Mamba Date: Thu, 24 Sep 2020 14:57:31 +0100 Subject: [PATCH 21/33] Add URLopener stubs --- stdlib/3/urllib/request.pyi | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/stdlib/3/urllib/request.pyi b/stdlib/3/urllib/request.pyi index ef0de4869830..4ab9bdefb32f 100644 --- a/stdlib/3/urllib/request.pyi +++ b/stdlib/3/urllib/request.pyi @@ -261,6 +261,22 @@ class URLopener: reporthook: Optional[Callable[[int, int, int], None]] = ..., data: Optional[bytes] = ..., ) -> Tuple[str, Optional[Message]]: ... + def addheader(self, *args: Tuple[str, str]) -> None: ... # undocumented + def cleanup(self) -> None: ... # undocumented + def close(self) -> None: ... # undocumented + def http_error( + self, url: str, fp: IO[str], errcode: int, errmsg: str, headers: Mapping[str, str], data: Optional[bytes] = ... + ) -> Optional[Union[_UrlopenRet, addinfourl]]: ... # undocumented + def http_error_default( + self, url: str, fp: IO[str], errcode: int, errmsg: str, headers: Mapping[str, str] + ) -> Optional[Union[_UrlopenRet, addinfourl]]: ... # undocumented + def open_data(self, url: str, data: Optional[bytes] = ...) -> addinfourl: ... # undocumented + def open_file(self, url: str) -> addinfourl: ... # undocumented + def open_ftp(self, url: str) -> addinfourl: ... # undocumented + def open_http(self, url: str, data: Optional[bytes] = ...) -> Optional[Union[_UrlopenRet, addinfourl]]: ... # undocumented + def open_https(self, url: str, data: Optional[bytes] = ...) -> Optional[Union[_UrlopenRet, addinfourl]]: ... # undocumented + def open_local_file(self, url: str) -> addinfourl: ... # undocumented + def open_unknown_proxy(self, proxy: str, fullurl: str, data: Optional[bytes] = ...) -> None: ... # undocumented class FancyURLopener(URLopener): def prompt_user_passwd(self, host: str, realm: str) -> Tuple[str, str]: ... From 195264abbee5ed226d5f4ce3df560c6115621f53 Mon Sep 17 00:00:00 2001 From: Stacks-Mamba Date: Thu, 24 Sep 2020 15:19:49 +0100 Subject: [PATCH 22/33] Revert tweaks --- .travis.yml | 15 --------------- tests/mypy_selftest.py | 2 +- 2 files changed, 1 insertion(+), 16 deletions(-) diff --git a/.travis.yml b/.travis.yml index 2e75f030baef..853b49c002f6 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,21 +4,6 @@ python: 3.8 jobs: include: - - name: "mypy-selftest" - python: 3.6 - install: - - pip install -r requirements-tests-py3.txt - script: - - ./tests/mypy_selftest.py --platform=linux - - name: "py3-tests" - python: 3.6 - install: - - pip install -r requirements-tests-py3.txt - script: - - ./tests/pytype_test.py - - ./tests/stubtest_test.py - - ./tests/check_consistent.py - - flake8 - name: "mypy (typed-ast)" python: 3.7 install: pip install -U git+git://github.com/python/mypy git+git://github.com/python/typed_ast diff --git a/tests/mypy_selftest.py b/tests/mypy_selftest.py index 56ea619fa884..fd7f23b105bb 100755 --- a/tests/mypy_selftest.py +++ b/tests/mypy_selftest.py @@ -11,7 +11,7 @@ if __name__ == '__main__': with tempfile.TemporaryDirectory() as tempdir: dirpath = Path(tempdir) - subprocess.run(['python3', '-m', 'pip', 'install', 'typing'], check=True) + subprocess.run(['python2.7', '-m', 'pip', 'install', '--user', 'typing'], check=True) subprocess.run(['git', 'clone', '--depth', '1', 'git://github.com/python/mypy', str(dirpath / 'mypy')], check=True) subprocess.run([sys.executable, '-m', 'pip', 'install', '-U', '-r', From 1b26ae206af0eb03b7f4d11c69fc658800e7bcc4 Mon Sep 17 00:00:00 2001 From: Stacks-Mamba Date: Thu, 24 Sep 2020 15:59:20 +0100 Subject: [PATCH 23/33] Fix formatting --- stdlib/3/urllib/request.pyi | 57 ++++++++++++++++++++++++++++--------- 1 file changed, 44 insertions(+), 13 deletions(-) diff --git a/stdlib/3/urllib/request.pyi b/stdlib/3/urllib/request.pyi index 4ab9bdefb32f..2bb007c4a527 100644 --- a/stdlib/3/urllib/request.pyi +++ b/stdlib/3/urllib/request.pyi @@ -4,9 +4,25 @@ import sys from email.message import Message from http.client import HTTPMessage, HTTPResponse, _HTTPConnectionProtocol from http.cookiejar import CookieJar -from typing import IO, Any, Callable, ClassVar, Dict, List, Mapping, NoReturn, Optional, Sequence, Tuple, TypeVar, Union, overload, Pattern -from urllib.response import addinfourl +from typing import ( + IO, + Any, + Callable, + ClassVar, + Dict, + List, + Mapping, + NoReturn, + Optional, + Pattern, + Sequence, + Tuple, + TypeVar, + Union, + overload, +) from urllib.error import HTTPError +from urllib.response import addinfourl _T = TypeVar("_T") _UrlopenRet = Any @@ -101,7 +117,8 @@ class HTTPRedirectHandler(BaseHandler): self, req: Request, fp: IO[str], code: int, msg: int, headers: Mapping[str, str] ) -> Optional[_UrlopenRet]: ... def http_error_303( - self, req: Request, fp: IO[str], code: int, msg: int, headers: Mapping[str, str]) -> Optional[_UrlopenRet]: ... + self, req: Request, fp: IO[str], code: int, msg: int, headers: Mapping[str, str] + ) -> Optional[_UrlopenRet]: ... def http_error_307( self, req: Request, fp: IO[str], code: int, msg: int, headers: Mapping[str, str] ) -> Optional[_UrlopenRet]: ... @@ -215,14 +232,18 @@ class ftpwrapper: # undocumented class FTPHandler(BaseHandler): def ftp_open(self, req: Request) -> addinfourl: ... - def connect_ftp(self, user: str, passwd: str, host: str, port: int, dirs: str, timeout: float) -> ftpwrapper: ... # undocumented + def connect_ftp( + self, user: str, passwd: str, host: str, port: int, dirs: str, timeout: float + ) -> ftpwrapper: ... # undocumented class CacheFTPHandler(FTPHandler): def setTimeout(self, t: float) -> None: ... def setMaxConns(self, m: int) -> None: ... def check_cache(self) -> None: ... # undocumented def clear_cache(self) -> None: ... # undocumented - def connect_ftp(self, user: str, passwd: str, host: str, port: int, dirs: str, timeout: float) -> ftpwrapper: ... # undocumented + def connect_ftp( + self, user: str, passwd: str, host: str, port: int, dirs: str, timeout: float + ) -> ftpwrapper: ... # undocumented class UnknownHandler(BaseHandler): def unknown_open(self, req: Request) -> NoReturn: ... @@ -294,22 +315,24 @@ class FancyURLopener(URLopener): self, url: str, fp: IO[str], errcode: int, errmsg: str, headers: Mapping[str, str], data: Optional[bytes] = ... ) -> Optional[Union[_UrlopenRet, addinfourl]]: ... # undocumented def http_error_401( - self, url: str, + self, + url: str, fp: IO[str], errcode: int, errmsg: str, headers: Mapping[str, str], data: Optional[bytes] = ..., - retry: bool = ... + retry: bool = ..., ) -> Optional[_UrlopenRet]: ... # undocumented def http_error_407( - self, url: str, + self, + url: str, fp: IO[str], errcode: int, errmsg: str, headers: Mapping[str, str], data: Optional[bytes] = ..., - retry: bool = ... + retry: bool = ..., ) -> Optional[_UrlopenRet]: ... # undocumented def http_error_default( self, url: str, fp: IO[str], errcode: int, errmsg: str, headers: Mapping[str, str] @@ -317,7 +340,15 @@ class FancyURLopener(URLopener): def redirect_internal( self, url: str, fp: IO[str], errcode: int, errmsg: str, headers: Mapping[str, str], data: Optional[bytes] ) -> Optional[_UrlopenRet]: ... # undocumented - def retry_http_basic_auth(self, url: str, realm: str, data: Optional[bytes] = ...) -> Optional[_UrlopenRet]: ... # undocumented - def retry_https_basic_auth(self, url: str, realm: str, data: Optional[bytes] = ...) -> Optional[_UrlopenRet]: ... # undocumented - def retry_proxy_http_basic_auth(self, url: str, realm: str, data: Optional[bytes] = ...) -> Optional[_UrlopenRet]: ... # undocumented - def retry_proxy_https_basic_auth(self, url: str, realm: str, data: Optional[bytes] = ...) -> Optional[_UrlopenRet]: ... # undocumented + def retry_http_basic_auth( + self, url: str, realm: str, data: Optional[bytes] = ... + ) -> Optional[_UrlopenRet]: ... # undocumented + def retry_https_basic_auth( + self, url: str, realm: str, data: Optional[bytes] = ... + ) -> Optional[_UrlopenRet]: ... # undocumented + def retry_proxy_http_basic_auth( + self, url: str, realm: str, data: Optional[bytes] = ... + ) -> Optional[_UrlopenRet]: ... # undocumented + def retry_proxy_https_basic_auth( + self, url: str, realm: str, data: Optional[bytes] = ... + ) -> Optional[_UrlopenRet]: ... # undocumented From a1490be5fac2df293b392a6e121e4696f0d8519b Mon Sep 17 00:00:00 2001 From: Stacks-Mamba Date: Fri, 25 Sep 2020 08:07:23 +0100 Subject: [PATCH 24/33] Make requested changes --- stdlib/3/urllib/request.pyi | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/stdlib/3/urllib/request.pyi b/stdlib/3/urllib/request.pyi index 2bb007c4a527..84ec7e4b4457 100644 --- a/stdlib/3/urllib/request.pyi +++ b/stdlib/3/urllib/request.pyi @@ -100,7 +100,7 @@ class BaseHandler: class HTTPDefaultErrorHandler(BaseHandler): def http_error_default( - self, req: Request, fp: IO[str], code: int, msg: str, hdrs: Mapping[str, str] + self, req: Request, fp: IO[bytes], code: int, msg: str, hdrs: Mapping[str, str] ) -> HTTPError: ... # undocumented class HTTPRedirectHandler(BaseHandler): @@ -141,8 +141,8 @@ class HTTPPasswordMgr: def find_user_password(self, realm: str, authuri: str) -> Tuple[Optional[str], Optional[str]]: ... def is_suburi(self, base: str, test: str) -> bool: ... # undocumented def reduce_uri( - self, uri: Union[str, Sequence[str]], default_port: bool = ... - ) -> Tuple[Union[str, Sequence[str]], str]: ... # undocumented + self, uri: str, default_port: bool = ... + ) -> str: ... # undocumented class HTTPPasswordMgrWithDefaultRealm(HTTPPasswordMgr): def add_password(self, realm: Optional[str], uri: Union[str, Sequence[str]], user: str, passwd: str) -> None: ... @@ -220,7 +220,7 @@ class FileHandler(BaseHandler): names: ClassVar[Optional[Tuple[str, ...]]] # undocumented def file_open(self, req: Request) -> addinfourl: ... def get_names(self) -> Tuple[str, ...]: ... # undocumented - def open_local_file(self, req: Request) -> Optional[addinfourl]: ... # undocumented + def open_local_file(self, req: Request) -> addinfourl: ... # undocumented class DataHandler(BaseHandler): def data_open(self, req: Request) -> addinfourl: ... @@ -286,16 +286,16 @@ class URLopener: def cleanup(self) -> None: ... # undocumented def close(self) -> None: ... # undocumented def http_error( - self, url: str, fp: IO[str], errcode: int, errmsg: str, headers: Mapping[str, str], data: Optional[bytes] = ... - ) -> Optional[Union[_UrlopenRet, addinfourl]]: ... # undocumented + self, url: str, fp: IO[bytes], errcode: int, errmsg: str, headers: Mapping[str, str], data: Optional[bytes] = ... + ) -> _UrlopenRet: ... # undocumented def http_error_default( - self, url: str, fp: IO[str], errcode: int, errmsg: str, headers: Mapping[str, str] - ) -> Optional[Union[_UrlopenRet, addinfourl]]: ... # undocumented + self, url: str, fp: IO[bytes], errcode: int, errmsg: str, headers: Mapping[str, str] + ) -> _UrlopenRet: ... # undocumented def open_data(self, url: str, data: Optional[bytes] = ...) -> addinfourl: ... # undocumented def open_file(self, url: str) -> addinfourl: ... # undocumented def open_ftp(self, url: str) -> addinfourl: ... # undocumented - def open_http(self, url: str, data: Optional[bytes] = ...) -> Optional[Union[_UrlopenRet, addinfourl]]: ... # undocumented - def open_https(self, url: str, data: Optional[bytes] = ...) -> Optional[Union[_UrlopenRet, addinfourl]]: ... # undocumented + def open_http(self, url: str, data: Optional[bytes] = ...) -> _UrlopenRet: ... # undocumented + def open_https(self, url: str, data: Optional[bytes] = ...) -> _UrlopenRet: ... # undocumented def open_local_file(self, url: str) -> addinfourl: ... # undocumented def open_unknown_proxy(self, proxy: str, fullurl: str, data: Optional[bytes] = ...) -> None: ... # undocumented @@ -335,7 +335,7 @@ class FancyURLopener(URLopener): retry: bool = ..., ) -> Optional[_UrlopenRet]: ... # undocumented def http_error_default( - self, url: str, fp: IO[str], errcode: int, errmsg: str, headers: Mapping[str, str] + self, url: str, fp: IO[bytes], errcode: int, errmsg: str, headers: Mapping[str, str] ) -> addinfourl: ... # undocumented def redirect_internal( self, url: str, fp: IO[str], errcode: int, errmsg: str, headers: Mapping[str, str], data: Optional[bytes] From 74b6f047dee8bad678d04ed1d17788bb2b96e8a0 Mon Sep 17 00:00:00 2001 From: Stacks-Mamba Date: Fri, 25 Sep 2020 08:10:25 +0100 Subject: [PATCH 25/33] Fix formatting --- stdlib/3/urllib/request.pyi | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/stdlib/3/urllib/request.pyi b/stdlib/3/urllib/request.pyi index 84ec7e4b4457..22932d890149 100644 --- a/stdlib/3/urllib/request.pyi +++ b/stdlib/3/urllib/request.pyi @@ -140,9 +140,7 @@ class HTTPPasswordMgr: def add_password(self, realm: str, uri: Union[str, Sequence[str]], user: str, passwd: str) -> None: ... def find_user_password(self, realm: str, authuri: str) -> Tuple[Optional[str], Optional[str]]: ... def is_suburi(self, base: str, test: str) -> bool: ... # undocumented - def reduce_uri( - self, uri: str, default_port: bool = ... - ) -> str: ... # undocumented + def reduce_uri(self, uri: str, default_port: bool = ...) -> str: ... # undocumented class HTTPPasswordMgrWithDefaultRealm(HTTPPasswordMgr): def add_password(self, realm: Optional[str], uri: Union[str, Sequence[str]], user: str, passwd: str) -> None: ... From 31135d3d0258747344e1330ebaf603cc31531915 Mon Sep 17 00:00:00 2001 From: stackswithans Date: Mon, 9 Aug 2021 01:49:04 +0100 Subject: [PATCH 26/33] Add/modify pulldom annotations --- stdlib/xml/dom/pulldom.pyi | 57 ++++++++++++++++++++++++++------------ 1 file changed, 39 insertions(+), 18 deletions(-) diff --git a/stdlib/xml/dom/pulldom.pyi b/stdlib/xml/dom/pulldom.pyi index cdbe35540771..2e5eda7a0b76 100644 --- a/stdlib/xml/dom/pulldom.pyi +++ b/stdlib/xml/dom/pulldom.pyi @@ -1,26 +1,47 @@ -from typing import IO, Any +from _typeshed import DOMImplementation +from typing import IO, Any, Callable, Optional, Sequence +from typing_extensions import Literal +from xml.dom.minidom import Document, Element, Text from xml.sax.handler import ContentHandler from xml.sax.xmlreader import XMLReader -START_ELEMENT: str -END_ELEMENT: str -COMMENT: str -START_DOCUMENT: str -END_DOCUMENT: str -PROCESSING_INSTRUCTION: str -IGNORABLE_WHITESPACE: str -CHARACTERS: str +START_ELEMENT: Literal["START_ELEMENT"] +END_ELEMENT: Literal["END_ELEMENT"] +COMMENT: Literal["COMMENT"] +START_DOCUMENT: Literal["START_DOCUMENT"] +END_DOCUMENT: Literal["END_DOCUMENT"] +PROCESSING_INSTRUCTION: Literal["PROCESSING_INSTRUCTION"] +IGNORABLE_WHITESPACE: Literal["IGNORABLE_WHITESPACE"] +CHARACTERS: Literal["CHARACTERS"] + +DocumentFactory = DOMImplementation | None +Node = Document | Element | Text + +Event = tuple[ + Literal[ + Literal["START_ELEMENT"], + Literal["END_ELEMENT"], + Literal["COMMENT"], + Literal["START_DOCUMENT"], + Literal["END_DOCUMENT"], + Literal["PROCESSING_INSTRUCTION"], + Literal["IGNORABLE_WHITESPACE"], + Literal["CHARACTERS"], + ], + Node, +] class PullDOM(ContentHandler): - document: Any | None - documentFactory: Any + document: Document | None + documentFactory: DocumentFactory firstEvent: Any lastEvent: Any - elementStack: Any - push: Any - pending_events: Any - def __init__(self, documentFactory: Any | None = ...) -> None: ... - def pop(self): ... + elementStack: Sequence[Any] + pending_events: Sequence[Any] + def __init__(self, documentFactory: DocumentFactory = ...) -> None: ... + def push(self, Element) -> None: ... + def pop(self) -> Element: ... + def reset(self) -> None: ... def setDocumentLocator(self, locator) -> None: ... def startPrefixMapping(self, prefix, uri) -> None: ... def endPrefixMapping(self, prefix) -> None: ... @@ -52,8 +73,8 @@ class DOMEventStream: def __getitem__(self, pos): ... def __next__(self): ... def __iter__(self): ... - def expandNode(self, node) -> None: ... - def getEvent(self): ... + def getEvent(self) -> Event: ... + def expandNode(self, node: Node) -> None: ... def clear(self) -> None: ... class SAX2DOM(PullDOM): From 0a7a0e9c14868d2b21d3d7ce31e6b6dc702627b2 Mon Sep 17 00:00:00 2001 From: stackswithans Date: Mon, 9 Aug 2021 01:52:29 +0100 Subject: [PATCH 27/33] Fix imports --- stdlib/xml/dom/pulldom.pyi | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/stdlib/xml/dom/pulldom.pyi b/stdlib/xml/dom/pulldom.pyi index 2e5eda7a0b76..8a1d3813a932 100644 --- a/stdlib/xml/dom/pulldom.pyi +++ b/stdlib/xml/dom/pulldom.pyi @@ -1,7 +1,6 @@ -from _typeshed import DOMImplementation -from typing import IO, Any, Callable, Optional, Sequence +from typing import IO, Any, Sequence from typing_extensions import Literal -from xml.dom.minidom import Document, Element, Text +from xml.dom.minidom import Document, DOMImplementation, Element, Text from xml.sax.handler import ContentHandler from xml.sax.xmlreader import XMLReader From 5a3a27a8a17b269149921f02d246776a60311341 Mon Sep 17 00:00:00 2001 From: stackswithans Date: Mon, 9 Aug 2021 02:10:21 +0100 Subject: [PATCH 28/33] Fix union syntax bug --- stdlib/xml/dom/pulldom.pyi | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/stdlib/xml/dom/pulldom.pyi b/stdlib/xml/dom/pulldom.pyi index 8a1d3813a932..8d4269e26b35 100644 --- a/stdlib/xml/dom/pulldom.pyi +++ b/stdlib/xml/dom/pulldom.pyi @@ -1,4 +1,4 @@ -from typing import IO, Any, Sequence +from typing import IO, Any, Sequence, Union from typing_extensions import Literal from xml.dom.minidom import Document, DOMImplementation, Element, Text from xml.sax.handler import ContentHandler @@ -13,8 +13,8 @@ PROCESSING_INSTRUCTION: Literal["PROCESSING_INSTRUCTION"] IGNORABLE_WHITESPACE: Literal["IGNORABLE_WHITESPACE"] CHARACTERS: Literal["CHARACTERS"] -DocumentFactory = DOMImplementation | None -Node = Document | Element | Text +DocumentFactory = Union[DOMImplementation, None] +Node = Union[Document, Element, Text] Event = tuple[ Literal[ @@ -31,7 +31,7 @@ Event = tuple[ ] class PullDOM(ContentHandler): - document: Document | None + document: Union[Document, None] documentFactory: DocumentFactory firstEvent: Any lastEvent: Any From d3b2e47e38d959d6c04fcf39268e318daa4a0d4b Mon Sep 17 00:00:00 2001 From: stackswithans Date: Mon, 9 Aug 2021 02:14:17 +0100 Subject: [PATCH 29/33] Use typing module Tuple class --- stdlib/xml/dom/pulldom.pyi | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/stdlib/xml/dom/pulldom.pyi b/stdlib/xml/dom/pulldom.pyi index 8d4269e26b35..3661bd1614b1 100644 --- a/stdlib/xml/dom/pulldom.pyi +++ b/stdlib/xml/dom/pulldom.pyi @@ -1,4 +1,4 @@ -from typing import IO, Any, Sequence, Union +from typing import IO, Any, Sequence, Tuple, Union from typing_extensions import Literal from xml.dom.minidom import Document, DOMImplementation, Element, Text from xml.sax.handler import ContentHandler @@ -16,7 +16,7 @@ CHARACTERS: Literal["CHARACTERS"] DocumentFactory = Union[DOMImplementation, None] Node = Union[Document, Element, Text] -Event = tuple[ +Event = Tuple[ Literal[ Literal["START_ELEMENT"], Literal["END_ELEMENT"], From e6d883e40dd841562328926310ae63a2d8c6e536 Mon Sep 17 00:00:00 2001 From: stackswithans Date: Mon, 9 Aug 2021 02:22:11 +0100 Subject: [PATCH 30/33] Remove wrong annotation --- stdlib/xml/dom/pulldom.pyi | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/stdlib/xml/dom/pulldom.pyi b/stdlib/xml/dom/pulldom.pyi index 3661bd1614b1..4c75f0afc7fa 100644 --- a/stdlib/xml/dom/pulldom.pyi +++ b/stdlib/xml/dom/pulldom.pyi @@ -38,9 +38,7 @@ class PullDOM(ContentHandler): elementStack: Sequence[Any] pending_events: Sequence[Any] def __init__(self, documentFactory: DocumentFactory = ...) -> None: ... - def push(self, Element) -> None: ... def pop(self) -> Element: ... - def reset(self) -> None: ... def setDocumentLocator(self, locator) -> None: ... def startPrefixMapping(self, prefix, uri) -> None: ... def endPrefixMapping(self, prefix) -> None: ... @@ -68,12 +66,12 @@ class DOMEventStream: bufsize: int def __init__(self, stream: IO[bytes], parser: XMLReader, bufsize: int) -> None: ... pulldom: Any - def reset(self) -> None: ... def __getitem__(self, pos): ... def __next__(self): ... def __iter__(self): ... def getEvent(self) -> Event: ... def expandNode(self, node: Node) -> None: ... + def reset(self) -> None: ... def clear(self) -> None: ... class SAX2DOM(PullDOM): From 8ef92d51f99e66e1f5896b9b41c85fc31a10117a Mon Sep 17 00:00:00 2001 From: stackswithans Date: Mon, 9 Aug 2021 21:13:35 +0100 Subject: [PATCH 31/33] Make requested changes --- stdlib/xml/dom/pulldom.pyi | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/stdlib/xml/dom/pulldom.pyi b/stdlib/xml/dom/pulldom.pyi index 4c75f0afc7fa..de5210472660 100644 --- a/stdlib/xml/dom/pulldom.pyi +++ b/stdlib/xml/dom/pulldom.pyi @@ -13,10 +13,10 @@ PROCESSING_INSTRUCTION: Literal["PROCESSING_INSTRUCTION"] IGNORABLE_WHITESPACE: Literal["IGNORABLE_WHITESPACE"] CHARACTERS: Literal["CHARACTERS"] -DocumentFactory = Union[DOMImplementation, None] -Node = Union[Document, Element, Text] +_DocumentFactory = Union[DOMImplementation, None] +_Node = Union[Document, Element, Text] -Event = Tuple[ +_Event = Tuple[ Literal[ Literal["START_ELEMENT"], Literal["END_ELEMENT"], @@ -27,17 +27,17 @@ Event = Tuple[ Literal["IGNORABLE_WHITESPACE"], Literal["CHARACTERS"], ], - Node, + _Node, ] class PullDOM(ContentHandler): - document: Union[Document, None] - documentFactory: DocumentFactory + document: Document | None + documentFactory: _DocumentFactory firstEvent: Any lastEvent: Any elementStack: Sequence[Any] pending_events: Sequence[Any] - def __init__(self, documentFactory: DocumentFactory = ...) -> None: ... + def __init__(self, documentFactory: _DocumentFactory = ...) -> None: ... def pop(self) -> Element: ... def setDocumentLocator(self, locator) -> None: ... def startPrefixMapping(self, prefix, uri) -> None: ... @@ -69,8 +69,8 @@ class DOMEventStream: def __getitem__(self, pos): ... def __next__(self): ... def __iter__(self): ... - def getEvent(self) -> Event: ... - def expandNode(self, node: Node) -> None: ... + def getEvent(self) -> _Event: ... + def expand_Node(self, node: _Node) -> None: ... def reset(self) -> None: ... def clear(self) -> None: ... From 5379d82b7da4f3f5975e181553f52dd995be1039 Mon Sep 17 00:00:00 2001 From: stackswithans Date: Mon, 9 Aug 2021 21:24:50 +0100 Subject: [PATCH 32/33] Fix s&r error --- stdlib/xml/dom/pulldom.pyi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stdlib/xml/dom/pulldom.pyi b/stdlib/xml/dom/pulldom.pyi index de5210472660..41a59a644ce9 100644 --- a/stdlib/xml/dom/pulldom.pyi +++ b/stdlib/xml/dom/pulldom.pyi @@ -70,7 +70,7 @@ class DOMEventStream: def __next__(self): ... def __iter__(self): ... def getEvent(self) -> _Event: ... - def expand_Node(self, node: _Node) -> None: ... + def expand_node(self, node: _Node) -> None: ... def reset(self) -> None: ... def clear(self) -> None: ... From eddde00e2ab947a9bf5f5d1f4375a49a07790754 Mon Sep 17 00:00:00 2001 From: stackswithans Date: Mon, 9 Aug 2021 21:25:56 +0100 Subject: [PATCH 33/33] Fix typo --- stdlib/xml/dom/pulldom.pyi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stdlib/xml/dom/pulldom.pyi b/stdlib/xml/dom/pulldom.pyi index 41a59a644ce9..ce8816b4a98a 100644 --- a/stdlib/xml/dom/pulldom.pyi +++ b/stdlib/xml/dom/pulldom.pyi @@ -70,7 +70,7 @@ class DOMEventStream: def __next__(self): ... def __iter__(self): ... def getEvent(self) -> _Event: ... - def expand_node(self, node: _Node) -> None: ... + def expandNode(self, node: _Node) -> None: ... def reset(self) -> None: ... def clear(self) -> None: ...