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 the descriptor protocol #87

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

erikbern
Copy link
Collaborator

@erikbern erikbern commented Mar 28, 2023

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

@freider
Copy link
Contributor

freider commented Mar 28, 2023

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...

@erikbern
Copy link
Collaborator Author

erikbern commented Mar 28, 2023

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 modal-labs/modal-client#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 @property etc, we can still do that, I think – we just have to keep track of those annotations

@erikbern erikbern marked this pull request as draft March 28, 2023 14:22
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.

2 participants