-
Notifications
You must be signed in to change notification settings - Fork 16
Add 2 new Type Hinting functions for helping with function or Protocol Styled approaches #705
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 2 new Type Hinting functions for helping with function or Protocol Styled approaches #705
Conversation
Also added documentation on how the 2 new methods are to be utilized...
for more information, see https://pre-commit.ci
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #705 +/- ##
==========================================
- Coverage 99.26% 98.23% -1.03%
==========================================
Files 2 2
Lines 136 170 +34
Branches 11 13 +2
==========================================
+ Hits 135 167 +32
- Misses 0 2 +2
Partials 1 1
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
…s try an alternative approch.
for more information, see https://pre-commit.ci
Can't figure out what I did wrong to get |
I don't think coverage likes my new changes this time, this could be a problem... |
No need for this one anymore I solved it :) |
What do these changes do?
My old pull request I tried doing the previous day to
aiohttp
just wouldn't cut it, and it felt a little embarrassing to have to close it and start over :/There should first need to be a way to converse between 2 different Styles of writing functions as well as 2 different ways to send
ParamSpec
type hints through to aSignal
so that it ides like pyright would know how to carry them. This way type hinting is kept retained and we don't need to create any extreme changes toTraceConfig
on aiohttp such as overriding as member descriptors (maybe not the best approach here).Wanted to make sure users could see what kind of parameters were being passed through pyright or mypy no matter what the circumstances were, therefore I had decided to make sure these 2 two function were also heavily documented, know that it's not perfect but it's a start.
I created 2 different approaches to solve passing
ParamSpec
Keywords.Method 1 Passing via Function Signature
Method 2 Passing via Protocol
Probably the one everyone maintaining aiohttp wanted to see...
I was primarily looking for a way to make the protocol manipulatable and it took me about 2 to 3
hours of research and attempts to get it right and since we can't use function generics like in Python 3.12
This was the most creative idea I could come up with. Type hints passed, users can see what to send through
TraceConfig
, problem solved. The bonus is that using Generics makes the parameters manipulatable this is somethingthat aiohttp does with
TraceConfig
on a heavy scale. Type casting should also work as intended as well.Are there changes in behavior for the user?
There shouldn't be all I added were 2 new functions to ensure that users had a way to pass
ParamSpec
arguments to the Signal class that I had established as a result of reviving this library. This was the puzzle that needed solving. Having the full signature rather than aCallable
would help users to see & identify different keyword arguments and types if any are to be passed.Related issue number
TraceConfig
better (Refractor TraceConfig with a wrapper styled approach. aiohttp#11123) .Checklist
CONTRIBUTORS.txt
CHANGES
folder<issue_id>.<type>
for example (588.bugfix)issue_id
change it to the pr id after creating the pr.feature
: Signifying a new feature..bugfix
: Signifying a bug fix..doc
: Signifying a documentation improvement..removal
: Signifying a deprecation or removal of public API..misc
: A ticket has been closed, but it is not of interest to users.