Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Many pytype errors when importing classes from collections.abc instead of typing in typeshed #1096

Open
AlexWaygood opened this issue Dec 29, 2021 · 2 comments
Labels
bug cat: stubs and 3p type stubs and third-party types

Comments

@AlexWaygood
Copy link
Contributor

In python/typeshed#6688, I attempted to change the typeshed stubs to import objects from collections.abc instead of typing wherever possible. However, a number of errors were output by pytype if the typeshed stubs were changed to import certain objects from collections.abc instead of typing. Most errors were related to Sequence, Callable and Iterable. However, there were also a number of errors that were simply AssertionError, with no other explanation.

Here is the full output of typeshed CI's pytype test, which can be found here . I would try to get a full stacktrace and/or narrow down the errors somewhat, but I'm on a Windows machine, so cannot run pytype, sadly:

Run ./tests/pytype_test.py

Testing files with pytype...
Run again with --print-stderr to get the full stacktrace.
   25/2183 with   5 errors
   50/2183 with  10 errors
   75/2183 with  14 errors
  100/2183 with  16 errors
  125/2183 with  19 errors
  150/2183 with  19 errors
  175/2183 with  19 errors
  200/2183 with  21 errors
  225/2183 with  23 errors
  250/2183 with  25 errors
  275/2183 with  26 errors
  300/2183 with  28 errors
  325/2183 with  29 errors
  350/2183 with  29 errors
  375/2183 with  29 errors
  400/2183 with  30 errors
  425/2183 with  32 errors
  450/2183 with  32 errors
  475/2183 with  32 errors
  500/2183 with  32 errors
  525/2183 with  32 errors
  550/2183 with  32 errors
  575/2183 with  32 errors
  600/2183 with  32 errors
  625/2183 with  32 errors
  650/2183 with  32 errors
  675/2183 with  32 errors
  700/2183 with  32 errors
  725/2183 with  32 errors
  750/2183 with  32 errors
  775/2183 with  32 errors
  800/2183 with  32 errors
  825/2183 with  32 errors
  850/2183 with  32 errors
  875/2183 with  32 errors
  900/2183 with  32 errors
  925/2183 with  32 errors
  950/2183 with  32 errors
  975/2183 with  32 errors
  1000/2183 with  32 errors
  1025/2183 with  32 errors
  1050/2183 with  32 errors
  1075/2183 with  32 errors
  1100/2183 with  32 errors
  1125/2183 with  32 errors
  1150/2183 with  33 errors
  1175/2183 with  33 errors
  1200/2183 with  33 errors
  1225/2183 with  33 errors
  1250/2183 with  33 errors
  1275/2183 with  33 errors
  1300/2183 with  33 errors
  1325/2183 with  33 errors
  1350/2183 with  33 errors
  1375/2183 with  33 errors
  1400/2183 with  33 errors
  1425/2183 with  33 errors
  1450/2183 with  33 errors
  1475/2183 with  33 errors
  1500/2183 with  33 errors
  1525/2183 with  33 errors
  1550/2183 with  33 errors
  1575/2183 with  33 errors
  1600/2183 with  33 errors
  1625/2183 with  33 errors
  1650/2183 with  33 errors
  1675/2183 with  33 errors
  1700/2183 with  33 errors
  1725/2183 with  33 errors
  1750/2183 with  33 errors
  1775/2183 with  33 errors
  1800/2183 with  33 errors
  1825/2183 with  34 errors
  1850/2183 with  35 errors
  1875/2183 with  35 errors
  1900/2183 with  35 errors
  1925/2183 with  35 errors
  1950/2183 with  35 errors
  1975/2183 with  35 errors
  2000/2183 with  36 errors
  2025/2183 with  36 errors
  2050/2183 with  36 errors
  2075/2183 with  36 errors
  2100/2183 with  36 errors
  2125/2183 with  36 errors
  2150/2183 with  36 errors
  2175/2183 with  36 errors
Ran pytype with 2183 pyis, got 36 errors.
stdlib/__future__.pyi (3.9): pytype.load_pytd.BadDependencyError: No Sequence in module collections.abc, referenced from 'genericpath'
stdlib/_ast.pyi (3.9): pytype.load_pytd.BadDependencyError: No Sequence in module collections.abc, referenced from 'genericpath'
stdlib/_bisect.pyi (3.9): pytype.load_pytd.BadDependencyError: No Sequence in module collections.abc, referenced from 'genericpath'
stdlib/_codecs.pyi (3.9): pytype.load_pytd.BadDependencyError: No Sequence in module collections.abc, referenced from 'genericpath'
stdlib/_compression.pyi (3.9): AssertionError
stdlib/_socket.pyi (3.9): AssertionError
stdlib/_typeshed/__init__.pyi (3.9): pytype.load_pytd.BadDependencyError: Unreplaced NamedType: 'typing.Callable', referenced from '_typeshed'
stdlib/asyncio/__init__.pyi (3.9): AssertionError
stdlib/asyncio/base_events.pyi (3.9): AssertionError
stdlib/asyncio/base_futures.pyi (3.9): AssertionError
stdlib/asyncio/base_subprocess.pyi (3.9): AssertionError
stdlib/asyncio/base_tasks.pyi (3.9): AssertionError
stdlib/asyncio/events.pyi (3.9): AssertionError
stdlib/asyncio/unix_events.pyi (3.9): pytype.load_pytd.BadDependencyError: Unreplaced NamedType: 'typing.Callable', referenced from 'asyncio.unix_events'
stdlib/codecs.pyi (3.9): pytype.load_pytd.BadDependencyError: Unreplaced NamedType: 'typing.Callable', referenced from 'codecs'
stdlib/collections/abc.pyi (3.9): pytype.load_pytd.BadDependencyError: Unreplaced NamedType: 'typing.Callable', referenced from 'collections.abc'
stdlib/concurrent/futures/__init__.pyi (3.9): AssertionError
stdlib/ctypes/__init__.pyi (3.9): pytype.load_pytd.BadDependencyError: Unreplaced NamedType: 'typing.Callable', referenced from 'ctypes'
stdlib/dataclasses.pyi (3.9): AssertionError
stdlib/doctest.pyi (3.9): AttributeError: Class not found: typing.Iterable
stdlib/email/headerregistry.pyi (3.9): AssertionError
stdlib/email/policy.pyi (3.9): pytype.load_pytd.BadDependencyError: Unreplaced NamedType: 'typing.Callable', referenced from 'email.policy'
stdlib/functools.pyi (3.9): AssertionError
stdlib/importlib/abc.pyi (3.9): pytype.load_pytd.BadDependencyError: Unreplaced NamedType: 'typing.Callable', referenced from 'importlib.abc'
stdlib/inspect.pyi (3.9): AssertionError
stdlib/io.pyi (3.9): pytype.load_pytd.BadDependencyError: Unreplaced NamedType: 'typing.Callable', referenced from 'io'
stdlib/multiprocessing/__init__.pyi (3.9): pytype.load_pytd.BadDependencyError: Unreplaced NamedType: 'typing.Sequence', referenced from 'multiprocessing'
stdlib/multiprocessing/dummy/__init__.pyi (3.9): AssertionError
stdlib/os/__init__.pyi (3.9): pytype.load_pytd.BadDependencyError: Unreplaced NamedType: 'typing.Callable', referenced from 'os'
stdlib/threading.pyi (3.9): pytype.load_pytd.BadDependencyError: Unreplaced NamedType: 'typing.Callable', referenced from 'threading'
stdlib/tracemalloc.pyi (3.9): pytype.load_pytd.BadDependencyError: Unreplaced NamedType: 'typing.Sequence', referenced from 'tracemalloc'
stdlib/types.pyi (3.9): pytype.load_pytd.BadDependencyError: Unreplaced NamedType: 'typing.Callable', referenced from 'types'
stubs/caldav/caldav/davclient.pyi (3.9): AssertionError
stubs/requests/requests/models.pyi (3.9): AssertionError
stubs/requests/requests/sessions.pyi (3.9): AssertionError
stubs/six/six/moves/collections_abc.pyi (3.9): pytype.load_pytd.BadDependencyError: Unreplaced NamedType: 'typing.Callable', referenced from 'six.moves.collections_abc'
Error: Process completed with exit code 1.
@AlexWaygood
Copy link
Contributor Author

Update on this: I tried this again in python/typeshed#7635, and the number of pytype errors has gone down by quite a lot! This is the stack trace now:

stdlib/_compression.pyi (3.9): AssertionError
stdlib/_socket.pyi (3.9): AssertionError
stdlib/_typeshed/__init__.pyi (3.9): AssertionError
stdlib/dataclasses.pyi (3.9): AssertionError
stdlib/email/headerregistry.pyi (3.9): AssertionError
stdlib/functools.pyi (3.9): AssertionError
stdlib/inspect.pyi (3.9): AssertionError

@JelleZijlstra managed to track this down to two places:

  • Importing MutableSequence from collections.abc instead of typing in array.pyi.
  • Importing Mapping from collections.abc instead of typing in types.pyi.

For now, we can just keep those two as imports from typing, so this isn't a massive priority any more :)

@JelleZijlstra
Copy link
Contributor

To be a bit more precise, the crash is about base classes: array.array inherits from MutableSequence and types.MappingProxyType from Mapping. Importing those base classes from collections.abc is what causes trouble.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug cat: stubs and 3p type stubs and third-party types
Projects
None yet
Development

No branches or pull requests

3 participants