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

Support most callables #133

Merged
merged 4 commits into from
Feb 19, 2024
Merged

Support most callables #133

merged 4 commits into from
Feb 19, 2024

Conversation

jl-wynen
Copy link
Member

Fixes #114

@jl-wynen jl-wynen mentioned this pull request Feb 16, 2024
Base automatically changed from decorated-providers to main February 16, 2024 13:59
Copy link
Member

@SimonHeybrock SimonHeybrock left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing a test with classmethod?

Comment on lines 290 to 294
if isinstance(func, type):
raise TypeError(
"Classes are not supported as providers because their type annotations "
f"cannot reliably be extracted. Got class {func}. "
"Consider using a free function, classmethod, or staticmethod."
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it worth mentioning that this is about classes, not class instances? While clear to us, an average user may forget to instantiate a class and not know the difference?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Better?

Comment on lines +317 to +321
# Drop `self` / `cls`
args = args[1:]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if this is a staticmethod? Does this actually take the inspect.isfunction branch?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. See

def test_pipeline_static_method_provider(deco: Callable[..., Any]) -> None:

@jl-wynen
Copy link
Member Author

Missing a test with classmethod?

No, it's here:

def test_pipeline_class_method_provider(deco: Callable[..., Any]) -> None:

@jl-wynen jl-wynen force-pushed the support-all-callables branch from 1a75b95 to b36dfa9 Compare February 19, 2024 09:13
@jl-wynen jl-wynen merged commit 8467e25 into main Feb 19, 2024
5 checks passed
@jl-wynen jl-wynen deleted the support-all-callables branch February 19, 2024 09:33
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.

Allow objects as providers
2 participants