Skip to content

Fix NewProtocol classmethod and staticmethod signatures#55

Merged
dnwpark merged 5 commits intomainfrom
callable-type-signature
Jan 26, 2026
Merged

Fix NewProtocol classmethod and staticmethod signatures#55
dnwpark merged 5 commits intomainfrom
callable-type-signature

Conversation

@dnwpark
Copy link
Copy Markdown
Contributor

@dnwpark dnwpark commented Jan 26, 2026

  • During get_local_defns we lose track of the origin of classmethod and staticmethod functions.
  • Fixing this means we need to properly handle these in _callable_type_to_signature
  • Also override the type of cls to type[Self]

@dnwpark dnwpark requested a review from msullivan January 26, 2026 21:04
@vercel
Copy link
Copy Markdown

vercel bot commented Jan 26, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Review Updated (UTC)
python-typemap Ready Ready Preview, Comment Jan 26, 2026 9:04pm

# An annoying thing to know is that for a member classmethod of C,
# cls *should* be type[C], but if it was not explicitly annotated, it
# will be C.
cls_param = Param[typing.Literal["cls"], type[typing.Self], quals]
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we want to override with typing.Self instead of using what was already there?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

type[Self] makes the annotations simpler and makes things easier when combining protocols which may have different receivers. We can use GetDefiner if we really need the actual class.

@dnwpark dnwpark merged commit 08eea2d into main Jan 26, 2026
4 of 5 checks passed
@dnwpark dnwpark deleted the callable-type-signature branch January 26, 2026 22:07
@msullivan
Copy link
Copy Markdown
Collaborator

msullivan commented Jan 26, 2026 via email

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