Support the descriptor protocol - #87
Conversation
|
Ohhhh, this would definitely mess up a lot of the type stub stuff. The type stubs PR looks at each entity in a wrapped class and emits a verbatim @staticmethod or @Property decorator in the stub. It also uses the somewhat magic "sigtools" library to extract actual combined signatures of wrapper-chains, and I'm not sure if that would work out of the box with this. Should hopefully fixable by setting some extra attributes on the wrapper or something... |
Let me park this PR for a bit and we can revisit it in a few weeks. I started working on it because I needed to fix a hack in https://github.com/modal-labs/modal-client/blob/main/modal_utils/decorator_utils.py in order to support https://github.com/modal-labs/modal-client/pull/434 and it turns out the "proper" way to implement the decorator thing is to use the descriptor protocol – however synchronicity doesn't support it. If we want to preserve annotations such as |
Gets rid of custom support for methods, properties, staticmethods, in favor of general support for the descriptor protocol. Actually a net reduction in complexity since we don't have to deal with a bunch of special cases.
Doesn't pass all tests because of a minor thing preserving the signature of the function.
Probably won't merge this, but it's a bit of yak shaving needed for something in the modal-client. I might shortcut it in the client and leave this one up for now, since it's a pretty big change and may interfere with @freider's work