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

Spike/typing #199

Draft
wants to merge 8 commits into
base: feat/scoped-resolution
Choose a base branch
from
Draft

Spike/typing #199

wants to merge 8 commits into from

Conversation

bobthemighty
Copy link
Owner

No description provided.

@bobthemighty bobthemighty changed the base branch from main to feat/scoped-resolution January 12, 2025 20:57
Copy link

codecov bot commented Jan 12, 2025

Codecov Report

Attention: Patch coverage is 73.80952% with 11 lines in your changes missing coverage. Please review.

Project coverage is 95.1%. Comparing base (9bd60dc) to head (0e5a6a3).
Report is 1 commits behind head on feat/scoped-resolution.

Files with missing lines Patch % Lines
punq/__init__.py 75.0% 8 Missing and 1 partial ⚠️
punq/_compat.py 66.6% 1 Missing and 1 partial ⚠️
Additional details and impacted files
@@                   Coverage Diff                    @@
##           feat/scoped-resolution    #199     +/-   ##
========================================================
- Coverage                   100.0%   95.1%   -4.9%     
========================================================
  Files                           2       2             
  Lines                         191     225     +34     
  Branches                       21      23      +2     
========================================================
+ Hits                          191     214     +23     
- Misses                          0       9      +9     
- Partials                        0       2      +2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@bobthemighty
Copy link
Owner Author

Fixes #189

Come slightly unstuck on the Protocol case, ie

class Service(Protocol):
    def do_thing(self):
        ...

class Impl:
    def do_thing(self):
        print("lulz")

container.register(Service, Impl) # Doesn't work because Impl isn't a Callable -> Service

Am I missing something?

@bobthemighty
Copy link
Owner Author

I think the problem is that a Protocol class isn't assignable to Type.

class Parent(Protocol):
    def do_something(self) -> None:
        pass

class Child:
    def do_something(self) -> None:
        print("Child doing something")


f: Callable[..., Parent] = Child

type checks happily, but

k: Type[Parser] = Parser

does not, which I think is why

container.register(Parser, ReverseParser)

fails its typecheck - Parser isn't a Type or a string

@bobthemighty
Copy link
Owner Author

    reveal_type(Parser)         # type[Parser]
    p: type[Parser] = Parser  # unassignable. lol. 

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.

1 participant