Skip to content
Discussion options

You must be logged in to vote

There's not a good way to do this and get all the behaviors you might want in Pyrefly today; supporting it is complicated and touches on underspecified behavior (it actually might be a struggle with any type checker today).

Let me first address the question of adding an attribute to a function: the solution there is generally to represent the extra attribute in terms of a callback protocol and make the decorator return it:

class FuncWithValidation[**P, R](Protocol):
    def __call__(self, *args: P.args, **kwargs: P.kwargs) -> R: ...
    _is_my_validation: Literal[True]

def my_validation[**P, R](func: Callable[P, R]) -> FuncWithValidation[P, R]:
    @wraps(func)
    def wrapper(cls, *args, 

Replies: 3 comments 1 reply

Comment options

You must be logged in to vote
1 reply
@stroxler
Comment options

stroxler Oct 6, 2025
Collaborator

Answer selected by JoanPuig
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants