Skip to content
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

Merged
merged 3 commits into from
Nov 25, 2023

Conversation

lucas-labs
Copy link
Contributor

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 is object.__init__

Closes: #45
Ref: #31

@codecov-commenter
Copy link

codecov-commenter commented Nov 23, 2023

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (6043b5b) 99.82% compared to head (754407c) 99.82%.

❗ 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.
📢 Have feedback on the report? Share it here.

@lucas-labs
Copy link
Contributor Author

🤭 oops, I forgot Protocol is a >=3.9 feature

@lucas-labs
Copy link
Contributor Author

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
Copy link
Contributor Author

@lucas-labs lucas-labs Nov 24, 2023

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

@RobertoPrevato
Copy link
Member

RobertoPrevato commented Nov 25, 2023

Hi @lucas-labs
I reviewed, it looks perfect! Thank You very much for this good contribution. I'll publish a new version to PyPi soon, maybe this weekend. :)
In the next days, since I recently updated the documentation of blacksheep v2 and released its v2 as stable, I can dedicate some time to write the documentation for rodi and add it to www.neoteroi.dev.

@RobertoPrevato RobertoPrevato merged commit 41037c7 into Neoteroi:main Nov 25, 2023
6 checks passed
@RobertoPrevato
Copy link
Member

@lucas-labs I just published a new version to PyPi. Thank You!

@lucas-labs
Copy link
Contributor Author

@RobertoPrevato That's awesome 🥳, thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Inner dependency not resolved when "parent" dependency extends from a protocol
3 participants