-
|
Hi, I have a custom decorator that looks like this: The aim is to mark certain class methods within a class as being validation methods. When I run pyrefly on it I get the following errors: What would be the correct way to write the annotation so that pyrefly understands the intent? Thanks, |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 1 reply
-
|
This one seems like a tricky case to handle, it uses dynamic features in Python that are tricky to model statically. We don't have a way to express "this decorator adds an attribute" in the Python type system. cc @stroxler or @grievejia for opinions here |
Beta Was this translation helpful? Give feedback.
-
|
This is definitely something we'd like to improve in Pyrefly, but unfortunately there are too many constraints and open questions about what the best behavior would be to really begin right now. |
Beta Was this translation helpful? Give feedback.
-
|
HI @yangdanny97 and @stroxler thanks a lot for the detailed explanation. I understand that this is a corner case and it will take some time to decide how to handle. I will keep an eye for future updates. |
Beta Was this translation helpful? Give feedback.
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: