-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
Use ParamSpec
for classmethod
and staticmethod
#9771
Conversation
This comment has been minimized.
This comment has been minimized.
Links to the primer hits:
These are all somewhat atypical use cases. Pytype crashes on this PR because they don't use typeshed's |
This comment has been minimized.
This comment has been minimized.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm
@rchen152, how difficult would the pytype crash be to fix? :) (There's no particular rush here on this one!) |
I believe all we need to do is copy the changes to builtins.pyi over to pytype's copy of the stub. I'll give it a try and let you know how it goes. |
See python/typeshed#9771 for context. PiperOrigin-RevId: 515480379
The builtins.pyi changes from this PR have been copied to pytype and released in version 2023.03.13. |
That seems to have done the trick — thank you very much! |
Diff from mypy_primer, showing the effect of this PR on open source code: pydantic (https://github.com/samuelcolvin/pydantic)
+ pydantic/_internal/_decorators.py:195: error: "classmethod" expects 3 type arguments, but 1 given [type-arg]
+ pydantic/_internal/_decorators.py:202: error: Need type annotation for "f_cls" [var-annotated]
+ pydantic/decorators.py:26: error: "classmethod" expects 3 type arguments, but 1 given [type-arg]
+ pydantic/decorators.py:48: error: "classmethod" expects 3 type arguments, but 1 given [type-arg]
+ pydantic/decorators.py:64: error: "classmethod" expects 3 type arguments, but 1 given [type-arg]
+ pydantic/decorators.py:73: error: "classmethod" expects 3 type arguments, but 1 given [type-arg]
+ pydantic/decorators.py:82: error: "classmethod" expects 3 type arguments, but 1 given [type-arg]
+ pydantic/decorators.py:92: error: "classmethod" expects 3 type arguments, but 1 given [type-arg]
+ pydantic/decorators.py:107: error: "classmethod" expects 3 type arguments, but 1 given [type-arg]
+ pydantic/decorators.py:131: error: "classmethod" expects 3 type arguments, but 1 given [type-arg]
+ pydantic/main.py:44: error: "classmethod" expects 3 type arguments, but 1 given [type-arg]
sympy (https://github.com/sympy/sympy)
+ sympy/polys/solvers.py:34: error: Cannot infer type of lambda [misc]
+ sympy/polys/solvers.py:34: error: Argument 1 to "staticmethod" has incompatible type "Callable[[Any], Any]"; expected "Callable[[Any, Any, Any, Any, Any, Any], Any]" [arg-type]
discord.py (https://github.com/Rapptz/discord.py)
- discord/ext/commands/cog.py:500: error: Incompatible types in assignment (expression has type "Callable[..., Any]", variable has type "FuncT") [assignment]
+ discord/ext/commands/cog.py:500: error: Incompatible types in assignment (expression has type "Callable[[VarArg(Any), KwArg(Any)], Any]", variable has type "FuncT") [assignment]
|
@samuelcolvin, just to give you a heads-up about this — this changes the stub for |
Thanks @AlexWaygood for pinging me. What's the time frame for this being released? Also, what's your recommendation for supporting this while keeping support for older versions? I'm a bit confused about where typeshed fits in to mypy, cpython, pyright etc. |
Most of CPython has no type annotations. Even for the parts of CPython that do have type annotations, type checkers ignore the type annotations in CPython, and only look to typeshed's stubs when it comes to type hints in the stdlib. Typeshed's stdlib stubs are vendored by mypy; mypy updates its vendored stdlib stubs to sync with typeshed's All other major type checkers also vendor typeshed's stdlib stubs in a very similar way. You may see pyright start to emit errors sooner than mypy, due to the fact that pyright has a much more frequent release schedule than mypy. (Again, I have no control over the mypy release process, I'm afraid! I'm not a mypy core dev.) When mypy 1.2 comes out, supporting the latest mypy version while maintaining support for older mypy versions might, admittedly, be a little tricky here. If that's something you want to do, I'd probably advise not parameterising - foo: classmethod[Any]`
+ foo: classmethod If you have I hope that's helpful, and sorry for the disruption caused! |
That's really helpful, it was the vendoring that was confusing me, since I couldn't remember seeing |
@samuelcolvin Also, as far as I can see, pydantic already pins mypy to a specific version. This is good. When you decide to update mypy, you will surely run it and fix all type annotations at that point. So, this should not break CI at unexpected times. |
Sadly not. We pin it in our tests, but we can't stop users from installing newer versions - hence lots of problems at the moment with mypy v1.1.1. There's no wayin packaging to say "X isn't required, but if is installed, it must be Y version". In v2 we might add an optional dependency group just to constrain the mypy version, e.g. |
The tracking issue for the mypy 1.2 release has just been opened: |
* update `AnyClassMethod` for change in python/typeshed#9771 * update mypy to use recent version of typeshed * Add comment to try to trigger CI * revert mypy version, add condition around AnyClassMethod --------- Co-authored-by: Adrian Garcia Badaracco <1755071+adriangb@users.noreply.github.com>
…rsion 1.10.8 Adrian Garcia Badaracco (1): Support for email-validator>=2.0.0.post2 (#5627) Amin Alaee (1): Remove pkg_resources test (#5508) Benoit C. Sirois (1): Fixes discriminated unions not working on aliased literal fields. Issue #3849. (#5736) David Montague (1): Fix internal error with mypy (#5449) Dimitri Papadopoulos Orfanos (1): Fix typos found by codespell (#5375) Hasan Ramezani (2): Fix Literal bug with typing-extension==4.6.0 (#5826) Prepare for 1.10.8 (#5830) Jens Heinrich (1): tweak type annotations (#5499) Kyle Finley (1): update `AnyClassMethod` for change in python/typeshed#9771 (#5505) Samuel Colvin (6): [ALPHA] V2 Alpha Blog Post (#5343) fix link in alpha release to v2 blog Add mike to V1 docs (#5628) enable fastapi testing on 1.10 (#5635) V1 add `build-docs.sh` (#5832) remove sponsors from docs (#5833)
https://build.opensuse.org/request/show/1088976 by user dgarcia + dimstar_suse - Update to v1.10.8 * Fix a bug in `Literal` usage with `typing-extension==4.6.0`, #5826 by @hramezani * This solves the (closed) issue #3849 where aliased fields that use discriminated union fail to validate when the data contains the non-aliased field name, #5736 by @benwah * Update email-validator dependency to >=2.0.0post2, #5627 by @adriangb * update `AnyClassMethod` for changes in [python/typeshed#9771](python/typeshed#9771), #5505 by @ITProKyle
…sion 1.10.10 Adrian Garcia Badaracco (1): Support for email-validator>=2.0.0.post2 (#5627) Amin Alaee (1): Remove pkg_resources test (#5508) Arseny Boykov (1): [1.10.x] Properly encode model and dataclass default for schema (#4781) Bas Schoenmaeckers (1): Add future and past date hypothesis strategies (#5850) Benoit C. Sirois (1): Fixes discriminated unions not working on aliased literal fields. Issue #3849. (#5736) David Montague (7): Disable Google analytics (#5059) prepare for v1.10.6 (#5157) Fix mypy plugin misbehavior with from_orm for user classes (#5193) Mypy plugin: Add implicit defaults for Field with no default argument (#5207) Fix mypy plugin crash (1.10.X-fixes) (#5208) prepare for 1.10.7 (#5248) Fix internal error with mypy (#5449) Dimitri Papadopoulos Orfanos (1): Fix typos found by codespell (#5375) Eric Jolibois (3): fix: support assignment on DataclassProxy (#4880) fix: avoid multiple calls of `__post_init__` when dataclasses are inherited (#4493) fix: use dataclasses proxy for frozen or empty dataclasses (#4878) Gulu Mammadli (1): fix: Fix broken link in the docs (Pydantic Models - Data Binding) (#5074) Hasan Ramezani (11): fix: missing file extension in model_config.md link (#4512) (#4513) Update mkdocs.yml (#4524) (#4532) v2 docs broken link fix (#4533) (#4550) Replace deprecated `get_event_loop` with `asyncio.run` (#4859) (#4860) Fix Literal bug with typing-extension==4.6.0 (#5826) Prepare for 1.10.8 (#5830) Add Pydantic classifier (#5847) [Backport] Fix Decimal trailing zero handling (#5968) Prepare for 1.10.9 (#6034) Add Pydantic `Json` field support to settings management (#6250) Prepare for 1.10.10 (#6308) Jens Heinrich (4): Fix wrong type for parameter (#5127) Mark optional params as Optional (#5128) Use getattr and default for qualname (#5126) tweak type annotations (#5499) Jon Parise (1): Allow dicts to have both patternProperties and additionalProperties (#4641) K900 (1): Fix racy doctests (#6103) Kurt McKee (1): Raise `ValidationError` for unhashable discriminator values (#5132) Kyle Finley (1): update `AnyClassMethod` for change in python/typeshed#9771 (#5505) Marc Mueller (3): [cherry-pick] Fix mypy plugin for 1.1.0 (#5077) (#5111) Don't apply dataclass transform twice with plugin + mypy 1.1.1 (#5162) [cherry-pick] Fix mypy plugin for 1.4.0 (#5927) (#5928) Marcelo Trylesinski (1): ✅ Update FastAPI test script (#6117) Markus Scheidgen (1): Fixed literal validator errors for unhashable values (#6194) MarkusSintonen (1): fix: Fix broken parametrized bases with GenericModels (#5052) Matt Fulgo (2): Allows Optional lists with unique_items check (#4568) Fix TypeError for GenericModel with Callable param (#4653) Mòrian (1): Add postgresql+psycopg as allowed scheme for PostgreDsn (#4689) (#4690) Samuel Colvin (26): test on the 1.10.X-fixes branch fix copy_on_model_validation type hint (#4491) use "field_specifiers", fix #4500 (#4501) add hooky config uprev 3.11, add check job (#4662) Add Jina AI to sponsors (#4767) bust CI cache, fix docs-build bust CI test cache (#4786) Moving docs to `docs.pydantic.dev` (#4818) Reduce binary sizes (#4862) fix history links (#4866) prepare for v1.10.3, fix #4552 Typing extensions min version (#4886) prepare for v1.10.4 release add dependencies-check to 1.10.X-fixes fix install step for dependencies check fix coverage badge to use correct branch (#5060) prepare for v1.10.5 Announcement (#5069) [ALPHA] V2 Alpha Blog Post (#5343) fix link in alpha release to v2 blog Add mike to V1 docs (#5628) enable fastapi testing on 1.10 (#5635) V1 add `build-docs.sh` (#5832) remove sponsors from docs (#5833) add roadmap to announcement (#6120) Serge Matveenko (1): 📌 Use Cython < v3 (#5845) Sigurd Spieckermann (1): [1.10.X] Fix field regex with StrictStr type annotation (#4538) Simon Matejetz (1): Fix creating schema from model using ConstrainedStr with regex str as dict key (#5223) Slava (1): Handle X | Y union in GenericModel (#4977) Volker Hilsenstein (1): Fix broken cross-references (#4743) github-actions[bot] (12): Fix "trough" typo in Model Config docs (#4593) (#4594) Add missing typing to example (#4596) (#4605) Fix improper parsing of Enum document (#4736) Renaming BaseModel (#4766) fix typo in docs (#4765) Remove trailing "```" (#4799) (#4800) Add newline before `Outputs:` when printing json output in docs (#4802) (#4848) Fix typo in types usage documentation. (#4825) (#4849) fixed documentation typo (#4855) (#4858) Fixed datetime format specifier in docs (#4876) (#4879) Fix typo in Field function docstring (#4931) (#4932) Invalidate mypy cache if config changes (#5007) (#5023) gou177 (1): fix: Parsing of custom root models (#4883) (#4884) javibookline (1): Discriminated union literal enum values (#5188) kgolawski (1): Fix code typo in docs (#4775) mark-todd (1): Bug fix for forward refs in generics (#6157) mbillingr (1): Dataclass deepcopy 1.10 (#4963) ⬢ Samuel Colvin (3): remove remains of ads, add custom analytics (#4927) simplify analytics more (#4930) uprev mkdocs-material, fix maxcdn errors (#4954)
Fixes #7689. Fixes #7134 (as much as we're ever going to fix, anyway). Cc. @NeilGirdhar.