-
Notifications
You must be signed in to change notification settings - Fork 258
Add assert_type #1103
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
Add assert_type #1103
Conversation
|
||
else: | ||
def assert_type(__val, __typ): | ||
"""Assert (to the type checker) that the value is of the given type. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
More a critique of the original PR, but not sure that "Assert (to the type checker) that the value is of the given type." is the least confusing phrasing.
You're not telling the type checker a fact, you're asking it to confirm one, so maybe "Ask a static type checker to confirm that the value is of the given type".
Or at least, we should do more to distinguish it from assert isinstance(val, typ)
(whose behaviour is what I would describe as "asserting something to the type checker")
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you bring this up on cpython instead? The docstring here is just a copy of the CPython one. We can sync it back later if we want.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure. Should I open a PR directly against the original BPO or would you prefer I file its own BPO
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can keep the same one
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One nit, but LGTM.
See python/cpython#30843