From 451d35739c0e620dcece10c31b2b3d15d6b6ced4 Mon Sep 17 00:00:00 2001 From: junkmd Date: Mon, 29 Aug 2022 21:30:17 +0900 Subject: [PATCH 1/6] add and migrate --- stdlib/_ctypes.pyi | 7 +++++++ stdlib/ctypes/__init__.pyi | 4 ++-- tests/stubtest_allowlists/py3_common.txt | 6 ------ 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/stdlib/_ctypes.pyi b/stdlib/_ctypes.pyi index 99e3ea52aba7..0ad2fcb571b8 100644 --- a/stdlib/_ctypes.pyi +++ b/stdlib/_ctypes.pyi @@ -2,6 +2,13 @@ import sys from ctypes import _CArgObject, _PointerLike from typing_extensions import TypeAlias +FUNCFLAG_CDECL: int +FUNCFLAG_PYTHONAPI: int +FUNCFLAG_USE_ERRNO: int +FUNCFLAG_USE_LASTERROR: int +RTLD_GLOBAL: int +RTLD_LOCAL: int + if sys.version_info >= (3, 11): CTYPES_MAX_ARGCOUNT: int diff --git a/stdlib/ctypes/__init__.pyi b/stdlib/ctypes/__init__.pyi index 48694fc6cf8a..68626d1e8b60 100644 --- a/stdlib/ctypes/__init__.pyi +++ b/stdlib/ctypes/__init__.pyi @@ -5,6 +5,8 @@ from collections.abc import Callable, Iterable, Iterator, Mapping, Sequence from typing import Any, ClassVar, Generic, TypeVar, Union as _UnionT, overload from typing_extensions import TypeAlias +from _ctypes import RTLD_GLOBAL as RTLD_GLOBAL, RTLD_LOCAL as RTLD_LOCAL + if sys.version_info >= (3, 9): from types import GenericAlias @@ -12,8 +14,6 @@ _T = TypeVar("_T") _DLLT = TypeVar("_DLLT", bound=CDLL) _CT = TypeVar("_CT", bound=_CData) -RTLD_GLOBAL: int -RTLD_LOCAL: int DEFAULT_MODE: int class CDLL: diff --git a/tests/stubtest_allowlists/py3_common.txt b/tests/stubtest_allowlists/py3_common.txt index aeccb4be26e0..62edc2a51cf5 100644 --- a/tests/stubtest_allowlists/py3_common.txt +++ b/tests/stubtest_allowlists/py3_common.txt @@ -341,16 +341,10 @@ wave.Wave_write.initfp _ctypes.Array _ctypes.CFuncPtr -_ctypes.FUNCFLAG_CDECL -_ctypes.FUNCFLAG_PYTHONAPI -_ctypes.FUNCFLAG_USE_ERRNO -_ctypes.FUNCFLAG_USE_LASTERROR _ctypes.POINTER _ctypes.PyObj_FromPtr _ctypes.Py_DECREF _ctypes.Py_INCREF -_ctypes.RTLD_GLOBAL -_ctypes.RTLD_LOCAL _ctypes.Structure _ctypes.Union _ctypes.addressof From 218c5ff7a7e808bb12252230412d161239ded841 Mon Sep 17 00:00:00 2001 From: junkmd Date: Mon, 29 Aug 2022 22:40:37 +0900 Subject: [PATCH 2/6] add workarounds to `tests\pytype_exclude_list.txt` --- tests/pytype_exclude_list.txt | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tests/pytype_exclude_list.txt b/tests/pytype_exclude_list.txt index fd47c9ec0dc9..88180f31e607 100644 --- a/tests/pytype_exclude_list.txt +++ b/tests/pytype_exclude_list.txt @@ -10,6 +10,10 @@ stubs/mysqlclient/MySQLdb/__init__.pyi stubs/mysqlclient/MySQLdb/connections.pyi stubs/mysqlclient/MySQLdb/cursors.pyi +# errors about the circular imports +stdlib/ctypes/__init__.pyi +stdlib/_ctypes.pyi + # _pb2.pyi have some constructs that break pytype # Eg # pytype.pyi.parser.ParseError: File: "/Users/nipunn/src/typeshed/third_party/2and3/google/protobuf/descriptor_pb2.pyi", line 195 From 756e129056b323310034fd24f944d8d9655ddbd8 Mon Sep 17 00:00:00 2001 From: junkmd Date: Mon, 29 Aug 2022 22:42:11 +0900 Subject: [PATCH 3/6] fix typo --- tests/pytype_exclude_list.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/pytype_exclude_list.txt b/tests/pytype_exclude_list.txt index 88180f31e607..359c58377e18 100644 --- a/tests/pytype_exclude_list.txt +++ b/tests/pytype_exclude_list.txt @@ -10,7 +10,7 @@ stubs/mysqlclient/MySQLdb/__init__.pyi stubs/mysqlclient/MySQLdb/connections.pyi stubs/mysqlclient/MySQLdb/cursors.pyi -# errors about the circular imports +# errors about circular imports stdlib/ctypes/__init__.pyi stdlib/_ctypes.pyi From 5214b97b824e21a5cdf44bbec9ec5a79681e5df6 Mon Sep 17 00:00:00 2001 From: junkmd Date: Mon, 29 Aug 2022 22:48:52 +0900 Subject: [PATCH 4/6] add other `ctypes` modules exclude_list --- tests/pytype_exclude_list.txt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/pytype_exclude_list.txt b/tests/pytype_exclude_list.txt index 359c58377e18..464b145fe34d 100644 --- a/tests/pytype_exclude_list.txt +++ b/tests/pytype_exclude_list.txt @@ -12,6 +12,8 @@ stubs/mysqlclient/MySQLdb/cursors.pyi # errors about circular imports stdlib/ctypes/__init__.pyi +stdlib/ctypes/util.pyi +stdlib/ctypes/wintypes.pyi stdlib/_ctypes.pyi # _pb2.pyi have some constructs that break pytype From 34dfbc11f7e62df0d9d87483a4be6fceef37dac0 Mon Sep 17 00:00:00 2001 From: Akuli Date: Mon, 29 Aug 2022 17:16:58 +0300 Subject: [PATCH 5/6] Let's try a thing --- stdlib/ctypes/__init__.pyi | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/stdlib/ctypes/__init__.pyi b/stdlib/ctypes/__init__.pyi index 68626d1e8b60..19465e084dee 100644 --- a/stdlib/ctypes/__init__.pyi +++ b/stdlib/ctypes/__init__.pyi @@ -5,7 +5,9 @@ from collections.abc import Callable, Iterable, Iterator, Mapping, Sequence from typing import Any, ClassVar, Generic, TypeVar, Union as _UnionT, overload from typing_extensions import TypeAlias -from _ctypes import RTLD_GLOBAL as RTLD_GLOBAL, RTLD_LOCAL as RTLD_LOCAL +# TODO: import these from _ctypes once it no longer breaks pytype +RTLD_GLOBAL: int +RTLD_LOCAL: int if sys.version_info >= (3, 9): from types import GenericAlias From ce023c00989a0ffaf0880e185badfed5ad715a0b Mon Sep 17 00:00:00 2001 From: Akuli Date: Mon, 29 Aug 2022 17:19:47 +0300 Subject: [PATCH 6/6] Update tests/pytype_exclude_list.txt --- tests/pytype_exclude_list.txt | 6 ------ 1 file changed, 6 deletions(-) diff --git a/tests/pytype_exclude_list.txt b/tests/pytype_exclude_list.txt index 464b145fe34d..fd47c9ec0dc9 100644 --- a/tests/pytype_exclude_list.txt +++ b/tests/pytype_exclude_list.txt @@ -10,12 +10,6 @@ stubs/mysqlclient/MySQLdb/__init__.pyi stubs/mysqlclient/MySQLdb/connections.pyi stubs/mysqlclient/MySQLdb/cursors.pyi -# errors about circular imports -stdlib/ctypes/__init__.pyi -stdlib/ctypes/util.pyi -stdlib/ctypes/wintypes.pyi -stdlib/_ctypes.pyi - # _pb2.pyi have some constructs that break pytype # Eg # pytype.pyi.parser.ParseError: File: "/Users/nipunn/src/typeshed/third_party/2and3/google/protobuf/descriptor_pb2.pyi", line 195