Skip to content

Spike/typing#199

Draft
bobthemighty wants to merge 8 commits into
feat/scoped-resolutionfrom
spike/typing
Draft

Spike/typing#199
bobthemighty wants to merge 8 commits into
feat/scoped-resolutionfrom
spike/typing

Conversation

@bobthemighty

Copy link
Copy Markdown
Owner

No description provided.

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

codecov Bot commented Jan 12, 2025

Copy link
Copy Markdown

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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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