-
-
Notifications
You must be signed in to change notification settings - Fork 402
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
Enhancement: ParsedSignature to enable TypeVar expansion using signature namespace #3206
Comments
We have litestar/litestar/utils/typing.py Lines 233 to 262 in ef9dbb7
|
I see, but litestar/litestar/utils/signature.py Line 214 in ef9dbb7
|
Not sure what you mean. I'm just pointing out that we have a utility that does type |
Sorry, I wasn't clear. Correct me if I am wrong, but I don't think that utility method gets called in the |
Obviously it was me who was unclear. I wasn't saying it did - just pointing out we have the utility you mentioned which maybe we can use. LMK how it goes. |
Ah thank you. Should I make a PR after adding it in? Sorry I am quite new to contributing to open source project. |
You are more than welcome to make a PR, cheers. To make it easier to review I'd first suggest creating a minimal example (I'm talking about something we can copy and paste and run without any extra work) that demonstrates the issue against |
Closed by #3242 |
Summary
ParsedSignature uses
typing.get_type_hints
which handles forward referencing but no TypeVar expansion. For instance,This makes it difficult to write type generic handlers as there is no way of expanding TypeVar. Both
pydantic
andmypy
use some forms of TypeVar expansion for the same scenario. A naive implementation can be as simple as this:Basic Example
As an example, to build a generic controller, this is what works currently (from #1311 and #2162)
Note how satanic the post handler looks. This works because
T.__name__
is resolved usingForwardRef
inget_type_hints
. Under the new proposal, it is possible to do this instead:Drawbacks and Impact
No response
Unresolved questions
No response
Note
While we are open for sponsoring on GitHub Sponsors and
OpenCollective, we also utilize Polar.sh to engage in pledge-based sponsorship.
Check out all issues funded or available for funding on our Polar.sh dashboard
The text was updated successfully, but these errors were encountered: