Thanks to visit codestin.com
Credit goes to github.com

Skip to content

3.14: add annotationlib, update typing and inspect #13985

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 11 commits into from
May 10, 2025

Conversation

JelleZijlstra
Copy link
Member

No description provided.

This comment has been minimized.

This comment has been minimized.

This comment has been minimized.

@AlexWaygood AlexWaygood changed the title 3.14: add annoationlib, update typing and inspect 3.14: add annotationlib, update typing and inspect May 10, 2025
@JelleZijlstra JelleZijlstra marked this pull request as ready for review May 10, 2025 16:04

This comment has been minimized.

Copy link
Collaborator

@srittau srittau left a comment

Choose a reason for hiding this comment

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

Looks mostly good, but could you comment the bare Anys? I don't think we need documentation for dict[str, Any] or the globals/locals, though.

@@ -27,6 +27,7 @@ def run_stubtest(typeshed_dir: Path) -> int:
"-m",
"mypy.stubtest",
"--check-typeshed",
"--show-traceback",
Copy link
Collaborator

Choose a reason for hiding this comment

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

I assume this is a testing remnant?

Copy link
Member Author

Choose a reason for hiding this comment

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

It was for testing but it seemed harmless to keep in.

This comment has been minimized.

@JelleZijlstra
Copy link
Member Author

could you comment the bare Anys?

I'm thinking of adding an alias _typeshed.AnnotationExpr = Any, what do you think? That would provide a way to annotate these in a more explicit way without repeating comments.

@srittau
Copy link
Collaborator

srittau commented May 10, 2025

Sounds like a good idea. I'm a fan of this kind of alias for Any.

@JelleZijlstra
Copy link
Member Author

Done. Also ended up making some more changes:

  • Add overloads by format to some function (e.g., return str in the STRING format; may return ForwardRef in the FORWARDREF format).
  • TypeVar.evaluate_bound etc. may be None
  • Use AnnotationForm in existing code too

Copy link
Contributor

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

ibis (https://github.com/ibis-project/ibis)
+ ibis/expr/operations/udf.py:143: error: Dict entry 0 has incompatible type "str": "Int64"; expected "str": "Argument"  [dict-item]

artigraph (https://github.com/artigraph/artigraph)
+ src/arti/types/python.py:145: error: Non-overlapping identity check (left operand type: "ParamSpec", right operand type: "<typing special form>")  [comparison-overlap]
+ src/arti/types/python.py:167: error: Non-overlapping identity check (left operand type: "ParamSpec", right operand type: "<typing special form>")  [comparison-overlap]

hydra-zen (https://github.com/mit-ll-responsible-ai/hydra-zen)
+ src/hydra_zen/_utils/coerce.py:111: error: Need type annotation for "list_caster_by_pos" (hint: "list_caster_by_pos: dict[<type>, <type>] = ...")  [var-annotated]
+ src/hydra_zen/_utils/coerce.py:112: error: Need type annotation for "list_caster_by_name" (hint: "list_caster_by_name: dict[<type>, <type>] = ...")  [var-annotated]
+ src/hydra_zen/_utils/coerce.py:149: error: Incompatible types in assignment (expression has type "type", variable has type "ParamSpec")  [assignment]

koda-validate (https://github.com/keithasaurus/koda-validate)
+ koda_validate/typehints.py:141: error: Non-overlapping identity check (left operand type: "ParamSpec", right operand type: "type[Just[A]]")  [comparison-overlap]

@JelleZijlstra JelleZijlstra merged commit 5ff32f3 into python:main May 10, 2025
72 checks passed
@JelleZijlstra
Copy link
Member Author

Oops I merged the moment the mypy-primer diff came in. Might revert a few bits to get rid of those.

@srittau
Copy link
Collaborator

srittau commented May 10, 2025

The primer hits are a bit suspect. They all seem related to get_origin, although that has only changed from Any to an alias of Any.

@JelleZijlstra
Copy link
Member Author

Yes it seems to pick the wrong overload of get_origin(). I tried to minimize this but haven't been able to. I'll revert that part of the PR for now.

JelleZijlstra added a commit to JelleZijlstra/typeshed that referenced this pull request May 10, 2025
@JelleZijlstra JelleZijlstra deleted the annotationlib branch May 10, 2025 21:47
hauntsaninja added a commit to hauntsaninja/typeshed that referenced this pull request May 11, 2025
hauntsaninja added a commit to hauntsaninja/typeshed that referenced this pull request May 11, 2025
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.

2 participants