Skip to content

Overwrite annotations for self and __init__#39

Merged
dnwpark merged 4 commits into
mainfrom
method-annotations
Jan 15, 2026
Merged

Overwrite annotations for self and __init__#39
dnwpark merged 4 commits into
mainfrom
method-annotations

Conversation

@dnwpark

@dnwpark dnwpark commented Jan 15, 2026

Copy link
Copy Markdown
Contributor
  • The return type of __init__ should always be None
  • The annotation for self can vary by type, but ends up being very verbose, and also annoying to deal with when generating new protocols. There is always GetDefiner as well.

@dnwpark dnwpark requested a review from msullivan January 15, 2026 16:46

@msullivan msullivan left a comment

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.

This seems fine for now but longer term we might need to do something else, like allow a specifically omitted annotation.

Comment on lines +434 to +448
params, ret = typing.get_args(typ)
params = [
(
p
if typing.get_args(p)[0] != typing.Literal["self"]
else Param[
typing.Literal["self"],
typing.Self,
typing.get_args(p)[2],
]
)
for p in params
]
ret = type(None) if name == "__init__" else ret
typ = typing.Callable[params, ret]

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.

Document what we are doing here

@msullivan

Copy link
Copy Markdown
Collaborator

Yeah I dunno, I am pretty unsure about this

@dnwpark dnwpark merged commit 59fff79 into main Jan 15, 2026
1 check passed
@dnwpark dnwpark deleted the method-annotations branch January 15, 2026 18:59
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