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

Recommend using PEP 585 #5055

Merged
merged 4 commits into from
Feb 24, 2021
Merged

Conversation

srittau
Copy link
Collaborator

@srittau srittau commented Feb 23, 2021

Also remove conventions enforced by black and remove old note about optional default arguments (now part of PEP 484 and enforced by CI).

Unfortunately, due to python/mypy#9980 we need a special rule for Tuple[x, ...].

Remove old note about optional default arguments (now part of
PEP 484 and enforced by CI)
@srittau
Copy link
Collaborator Author

srittau commented Feb 23, 2021

Weird that the pytype check fails here, while it succeeded in #5050.

CONTRIBUTING.md Outdated
* avoid invariant collection types (`List`, `Dict`) in argument
* use built-in generics (`list`, `dict`, `tuple`, `set`), instead
of importing them from `typing`, **except** for arbitrary length tuples
(`Tuple[int, ...]`);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be helpful here to link to the mypy issue, so we can easily refer back to it.

@JelleZijlstra
Copy link
Member

The pytype failures are strange:

stdlib/random.pyi (3.6): TypeError: unhashable type: 'list'
stdlib/secrets.pyi (3.6): TypeError: unhashable type: 'list'

@rchen152 do you know what could be causing this?

@rchen152
Copy link
Collaborator

The pytype failures are strange:

stdlib/random.pyi (3.6): TypeError: unhashable type: 'list'
stdlib/secrets.pyi (3.6): TypeError: unhashable type: 'list'

@rchen152 do you know what could be causing this?

They're strange because pytype is crashing :/

Traceback (most recent call last):
  [...]
  File "/usr/local/google/home/rechen/.venv_py38/lib/python3.8/site-packages/pytype/pytd/pytd.py", line 468, in _FlattenTypes
    unique = tuple(collections.OrderedDict.fromkeys(flattened))
  File "<attrs generated hash pytype.pytd.pytd.GenericType>", line 3, in __hash__
TypeError: unhashable type: 'list'

Looking.

rchen152 added a commit to google/pytype that referenced this pull request Feb 23, 2021
See python/typeshed#5055.

typeshed is moving toward using types from builtins and collections.abc rather
than typing (PEP 585). Mostly, this should just work with pytype, since we
rewrite typing.X to builtins.x anyway, and the collections.abc types are
represented as aliases of the typing ones.

However, typing.Callable has its own pytd node type, so we need to special-case
collections.abc.Callable in the parser. Since Tuple also has a special node
type, I added a test for Tuple as well - that appears to already be working.

PiperOrigin-RevId: 359096397
@rchen152
Copy link
Collaborator

This is fixed in pytype-2021.02.23. (I retriggered the pytype check, and it seems happy now.)

@JelleZijlstra
Copy link
Member

Awesome, thanks for the quick fix!

@JelleZijlstra JelleZijlstra merged commit c21329b into python:master Feb 24, 2021
@srittau srittau deleted the builtin-generics branch August 22, 2024 02:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants