Skip to content

Conversation

@wyattscarpenter
Copy link
Contributor

Closes #2020

``f: Callable[[object], object] = lambda x: x``

Type comments on function definitions do not actually work on lambda, nor do
normal type comments help (although you can use a type comment on an assignment
Copy link
Member

Choose a reason for hiding this comment

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

Might be better to not mention type comments? They're effectively deprecated, and in the context we're discussing I don't think they add anything over variable annotations.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

They are a random intrusion of esoterica here, but they are a potential answer to "where would the type annotations go?", so I think it makes sense to mention that they don't work.

Copy link
Member

Choose a reason for hiding this comment

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

I feel many readers probably won't even know what type comments are, so discussing them is more likely to confuse than to enlighten.

5. If you want to annotate the type of lambdas, you can bind them and annotate them
there.

6. Most type checkers have a setting that will warn you if anything gets deduced as
Copy link
Member

Choose a reason for hiding this comment

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

Could be useful to mention what those rules are for at least some type checkers (minimally mypy and pyright), so the guide is more practically useful.

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.

Indicate in the docs that static typing doesn't work with lambda functions

2 participants