| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
Sorry, something went wrong.
|
@gvanrossum this one is also ready I believe. Feedback on this function in https://mail.python.org/archives/list/typing-sig@python.org/thread/MITFQ6Z45RRMXY3HNM66IC3XXS3TA3JN/#MITFQ6Z45RRMXY3HNM66IC3XXS3TA3JN was positive. (I also proposed assert_error() there, but dropped it because of negative feedback.) |
Sorry, something went wrong.
|
It occurs to me that users of "assert_type()" may be surprised that it doesn't actually perform an assertion at runtime. Consider code like: from typing import assert_type
def parse_int(value) -> int:
# Hmm. A casual observer would likely read this incorrectly as `assert isinstance(value, str)`...
assert_type(value, str)
return int(value)
I wonder if we might consider a word other than "assert", or maybe add the word "static" somewhere. Suggestions:
|
Sorry, something went wrong.
|
That's a reasonable concern, but it's probably better discussed on the typing-sig thread. I'm happy to change the PR if there's consensus for another name. I'll note though that cast() has the same potential problem, and I haven't heard of confusion because of that. |
Sorry, something went wrong.
I'll plan to make a post tomorrow. |
Sorry, something went wrong.
|
@gvanrossum I think this should be ready to merge soon, since people on the typing-sig thread now seem on board with the assert_type name. I'd appreciate some more reviews for the documentation though, maybe @Fidget-Spinner or @AlexWaygood. |
Sorry, something went wrong.
I'll try to take a look soon! |
Sorry, something went wrong.
There was a problem hiding this comment.
Thanks! Looks pretty good, just a few thoughts :)
Sorry, something went wrong.
Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
|
Thanks for the review! |
Sorry, something went wrong.
There was a problem hiding this comment.
LGTM!
Sorry, something went wrong.
There was a problem hiding this comment.
Just 1 tiny nit:
Sorry, something went wrong.
Co-authored-by: David Foster <david@dafoster.net>
|
Planning to merge this tomorrow unless I get more feedback. |
Sorry, something went wrong.
Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
See python/cpython#30843. The implementation mostly follows that of cast(). It relies on `mypy.sametypes.is_same_type()`.
See python/cpython#30843. The implementation mostly follows that of cast(). It relies on `mypy.sametypes.is_same_type()`.
See python/cpython#30843. The implementation mostly follows that of cast(). It relies on `mypy.sametypes.is_same_type()`.
| Back | FazBrowse Home | New Git URL |
Another pending typing-sig proposal. This function serves as a static assertion to the type checker about the type of a value.
https://bugs.python.org/issue46480