tag:blogger.com,1999:blog-4195135246107166251.post1468618515324597653..comments2023-05-08T07:04:09.641-07:00Comments on Neopythonic: The AnyStr type variableGuido van Rossumhttp://www.blogger.com/profile/12821714508588242516noreply@blogger.comBlogger5125tag:blogger.com,1999:blog-4195135246107166251.post-38022790596216931282016-05-30T07:58:48.601-07:002016-05-30T07:58:48.601-07:00I've hacked something like `isinstance(obj, Un...I've hacked something like `isinstance(obj, Union[int, float])`: https://github.com/huntzhan/magic-constraintsAnonymoushttps://www.blogger.com/profile/13450168165432258247noreply@blogger.comtag:blogger.com,1999:blog-4195135246107166251.post-41016185025599725992016-05-18T11:56:19.423-07:002016-05-18T11:56:19.423-07:00Hobson: Thank you for the question. I have now ans...Hobson: Thank you for the question. I have now answered it at some length here: http://neopythonic.blogspot.com/2016/05/union-syntax.htmlGuido van Rossumhttps://www.blogger.com/profile/12821714508588242516noreply@blogger.comtag:blogger.com,1999:blog-4195135246107166251.post-3452608179059581792016-05-17T18:51:49.600-07:002016-05-17T18:51:49.600-07:00Wish there'd been a way to reuse existing synt...Wish there'd been a way to reuse existing syntax for a Union of types, like the tuple of types used in `except` and `isinstance`. `Union[str, bytes]` seems less obvious and lengthier than `(str, bytes)` or even `set(str, bytes)`.Hobsonhttps://www.blogger.com/profile/12560159237232637730noreply@blogger.comtag:blogger.com,1999:blog-4195135246107166251.post-70232343774249282462016-05-17T11:32:05.436-07:002016-05-17T11:32:05.436-07:00Here's a primer on type annotations for Python...Here's a primer on type annotations for Python 2: http://mypy.readthedocs.io/en/latest/python2.html. Also see the section in PEP 484: https://www.python.org/dev/peps/pep-0484/#suggested-syntax-for-python-2-7-and-straddling-codeGuido van Rossumhttps://www.blogger.com/profile/12821714508588242516noreply@blogger.comtag:blogger.com,1999:blog-4195135246107166251.post-59479801181756674502016-05-17T11:26:45.253-07:002016-05-17T11:26:45.253-07:00A very clear explanation, thanks!
BTW, given the ...A very clear explanation, thanks!<br /><br />BTW, given the large amount of existing 2.7-based projects that could benefit from gradually adding type annotation, it might be appropriate to show the comment-based syntax in one or two of the examples in this and similar posts.<br />Anonymoushttps://www.blogger.com/profile/07607158549124359981noreply@blogger.com