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

Update ast for 3.12 #10201

Merged
merged 5 commits into from Jun 3, 2023
Merged

Update ast for 3.12 #10201

merged 5 commits into from Jun 3, 2023

Conversation

JelleZijlstra
Copy link
Member

Split out from #10200 since this part appears to cause some pytype failures.

@github-actions

This comment has been minimized.

@@ -168,7 +168,7 @@ class NodeTransformer(NodeVisitor):
# The usual return type is AST | None, but Iterable[AST]
# is also allowed in some cases -- this needs to be mapped.

_T = TypeVar("_T", bound=AST)
_T = _TypeVar("_T", bound=AST)
Copy link
Member

Choose a reason for hiding this comment

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

Does pytype like it any more if we do _T = typing.TypeVar("_T")? (FWIW that would also be friendlier to flake8-pyi, which will recognise typing.TypeVar("_T") as a TypeVar declaration, but won't recognise _TypeVar("_T") as a TypeVar declaration.)

stdlib/_ast.pyi Outdated Show resolved Hide resolved
@rchen152
Copy link
Collaborator

As @JelleZijlstra suggested, the issue is probably that pytype doesn't recognize _TypeVar as TypeVar - there are some typing constructs that we match by name. Let me see if there's anything I can do about it.

@JelleZijlstra
Copy link
Member Author

Alex suggested that, not me :)

Thanks! I can try switching to typing.TypeVar for now.

@rchen152
Copy link
Collaborator

I have a fix for the pytype issue out for review. With any luck, I'll get it into this week's release.

rchen152 added a commit to google/pytype that referenced this pull request May 24, 2023
Adds support for aliasing names like TypeVar and simplifies name matching by
requiring the caller to pass in only one variant of a name (e.g.,
"typing.Callable") and having the matcher automatically try all variants
("Callable", "typing.Callable", "collections.abc.Callable").

See python/typeshed#10201 for motivation.

Fixes #1430.

PiperOrigin-RevId: 534721075
@rchen152
Copy link
Collaborator

I think pytype should be happy with from typing import TypeVar as _TypeVar with today's release (2023.5.24). Could you give it a try?

@rchen152
Copy link
Collaborator

Oh drat, it still seems broken =/ I'll look into it tomorrow.

@JelleZijlstra
Copy link
Member Author

JelleZijlstra commented May 25, 2023

Thanks! No hurry, we'll want to wait anyway until python/cpython#104799 gets resolved and I can always try the typing.TypeVar workaround.

@github-actions

This comment has been minimized.

@rchen152
Copy link
Collaborator

Ok, should actually be fixed now XD And I made sure to run pytype_test locally this time to check that the fix works. Will be in next week's pytype release.

Copy link
Member

@AlexWaygood AlexWaygood left a comment

Choose a reason for hiding this comment

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

Needs to be updated now that python/cpython#104974 is merged ;)

rchen152 added a commit to google/pytype that referenced this pull request May 31, 2023
I previously fixed the pyi parser's handling of `from typing import TypeVar as
_TypeVar`, but I neglected to check that the parsed ast could then be
successfully resolved by load_pytd.

Context: python/typeshed#10201.
PiperOrigin-RevId: 535500076
@github-actions

This comment has been minimized.

Copy link
Member

@AlexWaygood AlexWaygood left a comment

Choose a reason for hiding this comment

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

Looks good!

@rchen152
Copy link
Collaborator

rchen152 commented Jun 2, 2023

The pytype failure should actually be fixed now, in version 2023.6.2.

@github-actions
Copy link
Contributor

github-actions bot commented Jun 3, 2023

According to mypy_primer, this change has no effect on the checked open source code. 🤖🎉

@JelleZijlstra JelleZijlstra merged commit 628c88d into python:main Jun 3, 2023
62 checks passed
@JelleZijlstra JelleZijlstra deleted the ast312 branch June 3, 2023 00:11
@JelleZijlstra
Copy link
Member Author

Thanks @rchen152!

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.

None yet

3 participants