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

much simpler solution to extreme-self-casting #83

Closed
asottile opened this issue Jan 13, 2024 · 4 comments · Fixed by #101
Closed

much simpler solution to extreme-self-casting #83

asottile opened this issue Jan 13, 2024 · 4 comments · Fixed by #101

Comments

@asottile
Copy link
Contributor

this one felt a bit too easy -- I'm not sure how to change the problem to ...

spoilers
... require annotating [sic] `self`
from typing import *


class Fn[R, **P]:
    def __init__(self, f: Callable[P, R]):
        self.f = f

    def transform_callable(self) -> Callable[Concatenate[object, P], R]:
        ...
@laike9m
Copy link
Owner

laike9m commented Jan 15, 2024

Exactly 😃

Fn is a class decorator which takes a callable (`f`).

@laike9m
Copy link
Owner

laike9m commented Jan 15, 2024

The default solution is for Python < 3.12.

Though, not quite sure I totally get your point. If you mean to use solution2.py as the default solution, I'm fine with it (feel free to make a PR)

@asottile
Copy link
Contributor Author

here's a python < 3.12 solution which also doesn't require annotating self:

spoilers
from typing import *

R = TypeVar('R')
P = ParamSpec('P')


class Fn(Generic[R, P]):
    def __init__(self, f: Callable[P, R]):
        self.f = f

    def transform_callable(self) -> Callable[Concatenate[object, P], R]:
        ...

@laike9m
Copy link
Owner

laike9m commented Jan 22, 2024

Yep, looks good to me.

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 a pull request may close this issue.

2 participants