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

Add assert_type #1103

Merged
merged 4 commits into from Mar 22, 2022
Merged

Add assert_type #1103

merged 4 commits into from Mar 22, 2022

Conversation

JelleZijlstra
Copy link
Member


else:
def assert_type(__val, __typ):
"""Assert (to the type checker) that the value is of the given type.
Copy link
Collaborator

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")

Copy link
Member Author

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.

Copy link
Collaborator

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

Copy link
Member Author

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

Copy link
Collaborator

@srittau srittau left a 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.

typing_extensions/src/test_typing_extensions.py Outdated Show resolved Hide resolved
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants