Skip to content

Sync typeshed #14815

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

Merged
merged 5 commits into from
Mar 5, 2023
Merged

Sync typeshed #14815

merged 5 commits into from
Mar 5, 2023

Conversation

AlexWaygood
Copy link
Member

@AlexWaygood AlexWaygood commented Mar 1, 2023

Source commit: python/typeshed@257e287.

The automated PR by the bot failed again due to merge conflicts with the cherry-picked commits: https://github.com/python/mypy/actions/runs/4298562919/jobs/7492803753#step:5:53.

@github-actions

This comment has been minimized.

@AlexWaygood
Copy link
Member Author

Most of the hits here are from python/typeshed#6670. That typeshed commit solves a lot of issues for pyright, but it seems like it currently only causes false positives for mypy. Until mypy improves its support for ParamSpec, I'd be in favour of adding it to the typeshed changes we manually revert in our typeshed syncs. Thoughts on that?

@hauntsaninja
Copy link
Collaborator

Yeah, I'd be in favour of reverting it as well.

@AlexWaygood AlexWaygood marked this pull request as draft March 1, 2023 18:03
@AlexWaygood AlexWaygood marked this pull request as ready for review March 1, 2023 19:03
@github-actions

This comment has been minimized.

@AlexWaygood
Copy link
Member Author

@tmke8
Copy link
Contributor

tmke8 commented Mar 3, 2023

4 of the errors from the typeshed @wraps PR seem to just be due to the fact that _Wrapped doesn't define __name__:

  • the pandas error
  • the 2 spark errors
  • the streamlit error

Looking at the implementation of update_wrapper (which is the function that returns _Wrapped), I see that by default it will set ('__module__', '__name__', '__qualname__', '__doc__', '__annotations__') on the object it returns, which maybe implies that _Wrapped should have these attributes, though this can be customized with a parameter to update_wrapper...

@AlexWaygood
Copy link
Member Author

4 of the errors from the typeshed @wraps PR seem to just be due to the fact that _Wrapped doesn't define __name__:

  • the pandas error
  • the 2 spark errors
  • the streamlit error

Looking at the implementation of update_wrapper (which is the function that returns _Wrapped), I see that by default it will set ('__module__', '__name__', '__qualname__', '__doc__', '__annotations__') on the object it returns, which maybe implies that _Wrapped should have these attributes, though this can be customized with a parameter to update_wrapper...

Want to try making a typeshed PR?

@tmke8
Copy link
Contributor

tmke8 commented Mar 3, 2023

Sure.

@AlexWaygood
Copy link
Member Author

You can obviously cook up theoretical situations where adding __name__ to _Wrapped would cause false negatives:

>>> class Foo:
...     def __call__(self): ...
...
>>> class Bar:
...     def __call__(self): ...
...
>>> from functools import update_wrapper
>>> wrapped = Foo()
>>> wrapper = Bar()
>>> update_wrapper(wrapper, wrapped)
<__main__.Bar object at 0x000002CB493C9C50>
>>> _.__name__
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'Bar' object has no attribute '__name__'. Did you mean: '__ne__'?

But these seem pretty rare, and not worth worrying about. Adding __name__ (and friends) to _Wrapped sounds like a promising idea to me.

@AlexWaygood
Copy link
Member Author

AlexWaygood commented Mar 3, 2023

FWIW though, even if we make that change, I think I'd still want the changes to functools.wraps reverted in mypy's vendored version of typeshed. There's still too many other false positives imo.

@hauntsaninja
Copy link
Collaborator

Thanks, this looks good but we should probably resync with python/typeshed#9835 since that'll be another merge conflict

@AlexWaygood
Copy link
Member Author

python/typeshed#9815 will also cause merge conflicts for the next sync — any interest in taking a quick look at that one before I resync?

@AlexWaygood AlexWaygood marked this pull request as draft March 4, 2023 09:54
AlexWaygood and others added 5 commits March 4, 2023 13:06
This is allegedly causing large performance problems, see 13821

typeshed/8231 had zero hits on mypy_primer, so it's not the worst thing
to undo. Patching this in typeshed also feels weird, since there's a
more general soundness issue. If a typevar has a bound or constraint, we
might not want to solve it to a Literal.

If we can confirm the performance regression or fix the unsoundness
within mypy, I might pursue upstreaming this in typeshed.

(Reminder: add this to the sync_typeshed script once merged)
Since the plugin provides superior type checking:
python#13987 (comment)
@AlexWaygood AlexWaygood force-pushed the mypybot/sync-typeshed branch from ef82701 to cc24483 Compare March 4, 2023 13:15
@AlexWaygood AlexWaygood marked this pull request as ready for review March 4, 2023 13:21
@AlexWaygood AlexWaygood requested a review from hauntsaninja March 4, 2023 13:21
@github-actions
Copy link
Contributor

github-actions bot commented Mar 4, 2023

Diff from mypy_primer, showing the effect of this PR on open source code:

pip (https://github.com/pypa/pip)
+ src/pip/_internal/locations/_distutils.py:60: error: Unused "type: ignore" comment

hydra-zen (https://github.com/mit-ll-responsible-ai/hydra-zen)
+ src/hydra_zen/structured_configs/_utils.py:69: error: Name "get_origin" already defined (possibly by an import)  [no-redef]
- src/hydra_zen/structured_configs/_utils.py:69: error: All conditional function variants must have identical signatures  [misc]
- src/hydra_zen/structured_configs/_utils.py:69: note: Original:
- src/hydra_zen/structured_configs/_utils.py:69: note:     def get_origin(tp: Any) -> Optional[Any]
- src/hydra_zen/structured_configs/_utils.py:69: note: Redefinition:
- src/hydra_zen/structured_configs/_utils.py:69: note:     def get_origin(tp: Any) -> Optional[type]

pydantic (https://github.com/samuelcolvin/pydantic)
+ pydantic/_internal/_generate_schema.py:377: error: Unused "type: ignore" comment

@hauntsaninja hauntsaninja merged commit 9d84db2 into python:master Mar 5, 2023
@hauntsaninja
Copy link
Collaborator

Thanks!

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