-
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
fix: resolve protocols without needing to define init #46
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
❗ Your organization needs to install the Codecov GitHub app to enable full functionality. Additional details and impacted files@@ Coverage Diff @@
## main #46 +/- ##
=======================================
Coverage 99.82% 99.82%
=======================================
Files 2 2
Lines 560 565 +5
=======================================
+ Hits 559 564 +5
Misses 1 1 ☔ View full report in Codecov by Sentry. |
🤭 oops, I forgot |
I'll redownload python@3.8 tomorrow and check what's going on there |
from typing import _no_init_or_replace_init | ||
from typing import _no_init_or_replace_init as _no_init | ||
elif sys.version_info >= (3, 8): # pragma: no cover | ||
from typing import _no_init |
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.
So, Protocol
was introduced in Python 3.8, but since then it has changed the name of the function it uses as a default __init__
.
It was _no_init
in 3.8, but that changed quickly to _no_init_or_replace_init
for >=3.9
Hi @lucas-labs |
@lucas-labs I just published a new version to PyPi. Thank You! |
@RobertoPrevato That's awesome 🥳, thank you! |
When implementing a
Protocol
without defining its own__init__
method, a generic initialization method is generated autmatically (typing._no_init_or_replace_init
). This PR checks if the class being resolved has that specific__init__
on it, and if it does, makes rodi behave the same way it does for normal classes when its init isobject.__init__
Closes: #45
Ref: #31