From 77e5a2d4680341f20b351bc7d5554a8fa31ec1b6 Mon Sep 17 00:00:00 2001 From: Shantanu <12621235+hauntsaninja@users.noreply.github.com> Date: Sat, 5 Mar 2022 18:38:08 -0800 Subject: [PATCH] Upgrade to stubtest with dunder pos only reverted (#7442) --- .github/workflows/stubtest.yml | 2 +- .github/workflows/tests.yml | 9 ++++-- stubs/braintree/@tests/stubtest_allowlist.txt | 1 + .../cachetools/@tests/stubtest_allowlist.txt | 5 +++ .../frozendict/@tests/stubtest_allowlist.txt | 1 + stubs/ldap3/ldap3/operation/search.pyi | 2 ++ stubs/selenium/@tests/stubtest_allowlist.txt | 1 + .../selenium/selenium/webdriver/__init__.pyi | 1 + tests/stubtest_allowlists/py310.txt | 32 +------------------ tests/stubtest_third_party.py | 2 +- 10 files changed, 21 insertions(+), 35 deletions(-) create mode 100644 stubs/braintree/@tests/stubtest_allowlist.txt create mode 100644 stubs/selenium/@tests/stubtest_allowlist.txt diff --git a/.github/workflows/stubtest.yml b/.github/workflows/stubtest.yml index d092a9632..bf07eb794 100644 --- a/.github/workflows/stubtest.yml +++ b/.github/workflows/stubtest.yml @@ -39,7 +39,7 @@ jobs: # - get_mypy_req in tests/stubtest_third_party.py # - stubtest-stdlib in .github/workflows/stubtest.yml # - stubtest-stdlib in .github/workflows/tests.yml - run: pip install $(grep tomli== requirements-tests.txt) git+git://github.com/python/mypy@a562f0aac287b1069a8267b3812fb6813eaefec3 + run: pip install $(grep tomli== requirements-tests.txt) git+git://github.com/python/mypy@c7a81620bef7585cca6905861bb7ef34ec12da2f - name: Run stubtest run: python tests/stubtest_stdlib.py diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 08ee9405e..ce2157dda 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -114,7 +114,7 @@ jobs: # - get_mypy_req in tests/stubtest_third_party.py # - stubtest-stdlib in .github/workflows/stubtest.yml # - stubtest-stdlib in .github/workflows/tests.yml - run: pip install $(grep tomli== requirements-tests.txt) git+git://github.com/python/mypy@a562f0aac287b1069a8267b3812fb6813eaefec3 + run: pip install $(grep tomli== requirements-tests.txt) git+git://github.com/python/mypy@c7a81620bef7585cca6905861bb7ef34ec12da2f - name: Run stubtest run: python tests/stubtest_stdlib.py @@ -133,7 +133,12 @@ jobs: run: pip install $(grep tomli== requirements-tests.txt) - name: Run stubtest run: | - STUBS=$(git diff --name-only origin/${{ github.base_ref }} HEAD | egrep ^stubs/ | cut -d "/" -f 2 | sort -u | (while read stub; do [ -d stubs/$stub ] && echo $stub || true; done)) + STUBS=$( + git diff --name-only origin/${{ github.base_ref }} HEAD | + # Uncomment the following to (very slowly) run on all third party stubs: + # git ls-files | + egrep ^stubs/ | cut -d "/" -f 2 | sort -u | (while read stub; do [ -d stubs/$stub ] && echo $stub || true; done) + ) if test -n "$STUBS"; then echo "Testing $STUBS..." APT_PACKAGES=$(python tests/get_apt_packages.py $STUBS) diff --git a/stubs/braintree/@tests/stubtest_allowlist.txt b/stubs/braintree/@tests/stubtest_allowlist.txt new file mode 100644 index 000000000..f40932c48 --- /dev/null +++ b/stubs/braintree/@tests/stubtest_allowlist.txt @@ -0,0 +1 @@ +.*\.AttributeGetter.__repr__ # has an extra argument, but also a million things inherit from it diff --git a/stubs/cachetools/@tests/stubtest_allowlist.txt b/stubs/cachetools/@tests/stubtest_allowlist.txt index 878cbadf2..f4aafb87c 100644 --- a/stubs/cachetools/@tests/stubtest_allowlist.txt +++ b/stubs/cachetools/@tests/stubtest_allowlist.txt @@ -1,2 +1,7 @@ cachetools.Cache.get cachetools.cache.Cache.get + +# it looks like cachetools stubs are really out of date, so none of the modules +# referenced exist anymore +cachetools\..*\.__(get|set|del)item__ # has extra argument +cachetools\..*TTLCache.__repr__ diff --git a/stubs/frozendict/@tests/stubtest_allowlist.txt b/stubs/frozendict/@tests/stubtest_allowlist.txt index 6a780fb4e..eb99e759a 100644 --- a/stubs/frozendict/@tests/stubtest_allowlist.txt +++ b/stubs/frozendict/@tests/stubtest_allowlist.txt @@ -1,4 +1,5 @@ frozendict.FrozenOrderedDict frozendict.frozendict.__hash__ frozendict.frozendict.__new__ +frozendict.frozendict.__repr__ # forwards args to super frozendict.frozendict.copy diff --git a/stubs/ldap3/ldap3/operation/search.pyi b/stubs/ldap3/ldap3/operation/search.pyi index 78a728ed4..a929e13f3 100644 --- a/stubs/ldap3/ldap3/operation/search.pyi +++ b/stubs/ldap3/ldap3/operation/search.pyi @@ -22,6 +22,8 @@ class FilterNode: assertion: Any elements: Any def __init__(self, tag: Any | None = ..., assertion: Any | None = ...) -> None: ... + def __str__(self, pos: int = ...) -> str: ... + def __repr__(self, pos: int = ...) -> str: ... def append(self, filter_node): ... def evaluate_match(match, schema, auto_escape, auto_encode, validator, check_names): ... diff --git a/stubs/selenium/@tests/stubtest_allowlist.txt b/stubs/selenium/@tests/stubtest_allowlist.txt new file mode 100644 index 000000000..f9d836a85 --- /dev/null +++ b/stubs/selenium/@tests/stubtest_allowlist.txt @@ -0,0 +1 @@ +selenium.webdriver.__all__ # intentional diff --git a/stubs/selenium/selenium/webdriver/__init__.pyi b/stubs/selenium/selenium/webdriver/__init__.pyi index 8f2711601..c352e5e54 100644 --- a/stubs/selenium/selenium/webdriver/__init__.pyi +++ b/stubs/selenium/selenium/webdriver/__init__.pyi @@ -20,6 +20,7 @@ from .webkitgtk.options import Options as WebKitGTKOptions from .webkitgtk.webdriver import WebDriver as WebKitGTK # We need an explicit __all__ because some of the above won't otherwise be exported. +# This could also be fixed using assignments __all__ = [ "Firefox", "FirefoxProfile", diff --git a/tests/stubtest_allowlists/py310.txt b/tests/stubtest_allowlists/py310.txt index 911510b38..a4bfa1b67 100644 --- a/tests/stubtest_allowlists/py310.txt +++ b/tests/stubtest_allowlists/py310.txt @@ -9,36 +9,12 @@ _collections_abc.ValuesView.__reversed__ # These are not positional-only at runtime, but we treat them # as positional-only to match dict. -_collections_abc.Mapping.__getitem__ -_collections_abc.Mapping.__contains__ -_collections_abc.MutableMapping.__delitem__ -_collections_abc.MutableMapping.__setitem__ _collections_abc.MutableMapping.pop _collections_abc.MutableMapping.setdefault -# Many positional-only differences with KeysView/ItemsView -_collections_abc.dict_keys.__.*__ -_collections_abc.dict_items.__.*__ - -# Pos-only differences with object.__setattr__/object.__delattr__ -# Adding these to the stub has bad consequences (see #7385, #7347) -enum.EnumMeta.__setattr__ -enum.EnumMeta.__delattr__ -uuid.UUID.__setattr__ - -# Pos-only differences with the normal NamedTuple __getitem__ -platform.uname_result.__getitem__ - -# mypy does not autogenerate __eq__ methods for dataclasses, -# so wrongly infers that these have positional-only parameters. -# https://github.com/python/mypy/issues/12186 -pstats.FunctionProfile.__eq__ -pstats.StatsProfile.__eq__ - # typing.IO uses positional-or-keyword arguments, but in the stubs we prefer # to mark these as positional-only for compatibility with existing sub-classes. typing.BinaryIO.write -typing.IO.__exit__ typing.IO.read typing.IO.readline typing.IO.readlines @@ -132,17 +108,12 @@ xml.etree.cElementTree.XMLParser.__init__ # Defined in C so has general signatu # positional-only complaints caused by differences between typing aliases and the "real" classes in the stdlib _collections_abc.AsyncGenerator.asend _collections_abc.AsyncGenerator.athrow -_collections_abc.Container.__contains__ _collections_abc.Coroutine.send _collections_abc.Coroutine.throw _collections_abc.Generator.send _collections_abc.Generator.throw -_collections_abc.Mapping.__eq__ -_collections_abc.Set.__eq__ -contextlib.AbstractAsyncContextManager.__aexit__ -contextlib.AbstractContextManager.__exit__ -typing.SupportsRound.__round__ # pos-or-kw at runtime, but we pretend it's pos-only in the stub so that e.g. float.__round__ satisfies the interface +# typing.SupportsRound.__round__ # pos-or-kw at runtime, but we pretend it's pos-only in the stub so that e.g. float.__round__ satisfies the interface types.DynamicClassAttribute..* # In the stub we pretend it's an alias for property, but it has positional-only differences # These three have a pos-or-keyword first parameter at runtime, but deliberately have a pos-only first parameter in the stub. #6812 @@ -177,7 +148,6 @@ asynchat.__warningregistry__ # Removal planned for 3.12, can add if someone nee asyncio.AbstractEventLoop.connect_accepted_socket asyncio.events.AbstractEventLoop.connect_accepted_socket bdb.Breakpoint.clearBreakpoints -dbm.dumb._Database.__contains__ distutils.dist.DistributionMetadata.set_classifiers distutils.dist.DistributionMetadata.set_keywords distutils.dist.DistributionMetadata.set_platforms diff --git a/tests/stubtest_third_party.py b/tests/stubtest_third_party.py index 7fce6d856..5cbb6a3b0 100755 --- a/tests/stubtest_third_party.py +++ b/tests/stubtest_third_party.py @@ -22,7 +22,7 @@ def get_mypy_req(): # - get_mypy_req in tests/stubtest_third_party.py # - stubtest-stdlib in .github/workflows/stubtest.yml # - stubtest-stdlib in .github/workflows/tests.yml - return "git+git://github.com/python/mypy@a562f0aac287b1069a8267b3812fb6813eaefec3" + return "git+git://github.com/python/mypy@c7a81620bef7585cca6905861bb7ef34ec12da2f" with open("requirements-tests.txt") as f: return next(line.strip() for line in f if "mypy" in line)