-
Notifications
You must be signed in to change notification settings - Fork 17
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
Add Deprecated #34
base: main
Are you sure you want to change the base?
Add Deprecated #34
Conversation
Codecov Report
📣 This organization is not using Codecov’s GitHub App Integration. We recommend you install it so Codecov can continue to function properly for your repositories. Learn more @@ Coverage Diff @@
## main #34 +/- ##
===========================================
- Coverage 100.00% 96.38% -3.62%
===========================================
Files 1 2 +1
Lines 59 166 +107
Branches 5 47 +42
===========================================
+ Hits 59 160 +101
- Misses 0 6 +6
📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more |
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.
otherwise LGTM.
class Deprecate(BaseMetadata): | ||
"""Marks a parameter or field as deprecated""" | ||
|
||
message: str |
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.
maybe add the other parameters? But I don't mind that much.
@adriangb There is no active proposal for |
Right I made that up as something that could plausibly be returned by Would you make |
I'd be keen to move ahead with this - as part of solving pydantic/pydantic#2255. @Zac-HD WDYT? |
So cool! 🚀 My only thought is that I would like to work on my thingy I imagine there could be code/parameters that used both (I will in FastAPI and others), e.g.: def say_hi(
*,
name: Annotated[
str | None,
deprecated("Please use first_name"),
doc("The full name of the user"),
] = None,
first_name: Annotated[
str | None,
doc("The first name of the user")
] = None,
):
return "Hello" In this case, the new alias/generic |
I'm keen for annotated-types to support some way of expressing a deprecation, and matching the runtime and static-check-time semantics of an accepted PEP-702 would be a great way to do that. Implications:
I'd also prefer to require From reading the PEP I get the sense that @JelleZijlstra doesn't want to propose a new |
Great! Just to clarify a couple of things.
But having The thing I've been working on is a I think Jelle and I started working on both things at similar times and I didn't know about In short, the closer to "standard" would actually (probably) be
rather than
Just because And it would be compatible with my future wannabe-PEP-thing as in |
Can't you then do something like As far as this PR is concerned I agree with Zac that we might want to wait until (1) PEP 702 is accepted and (2) |
For me the main reason is that the vast majority of deprecations in the stdlib could be marked without I'm personally not too concerned about the strings point, but some type checker authors find this important. |
message: str | ||
|
||
|
||
Deprecated = Annotated[T, Deprecate(message='')] |
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.
Isn't having both Deprecate
and Deprecated
confusing? Someone may import the wrong one and do my_field: Annotated[str, Deprecated('')]
instead of my_field: Annotated[str, Deprecate('')]
.
I guess it will error right away so not this is not that important
So PEP 702 got accepted, and in its final form it does not support deprecating specific typed fields. Do you think this should still be implemented in |
I'd prefer not to implement anything in I've posted a comment on the CPython implementation PR about making this introspection easier. |
cc @tiangolo @JelleZijlstra @samuelcolvin
Open question: can we design this in a way to be compatible with the version of
@typing.deprecated
that returns something useful at runtime? It would be nice if it returns a class that we can insert into the bases of this one so that anyone doing something likefor annotation in annotations: ... isinstance(annotation, typing.Deprecated
is okay.