[Python-Dev] Please reject or postpone PEP 526 (original) (raw)
Ivan Levkivskyi levkivskyi at gmail.com
Sun Sep 4 07:56:46 EDT 2016
- Previous message (by thread): [Python-Dev] Please reject or postpone PEP 526
- Next message (by thread): [Python-Dev] Please reject or postpone PEP 526
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
On 4 September 2016 at 13:30, Mark Shannon <mark at hotpy.org> wrote:
It would be a real shame if PEP 526 mandates against checkers doing as good as job as possible. Forcing all uses of a variable to have the same type is a major and, IMO crippling, limitation.
E.g. def foo(x:Optional[int])->int: if x is None: return -1 return x + 1 If the type of the variable 'x' is Optional[int] then 'return x + 1' doesn't type check. If the type of the parameter 'x' is Optional[int] then a checker can readily verify the above code.
Mark,
First, in addition to the quote from my previous e-mail, I would like to show another quote from PEP 526 "This PEP does not require type checkers to change their type checking rules. It merely provides a more readable syntax to replace type comments"
Second, almost exactly your example has been added to PEP 484:
class Reason(Enum): timeout = 1 error = 2
def process(response: Union[str, Reason] = '') -> str: if response is Reason.timeout: return 'TIMEOUT' elif response is Reason.error: return 'ERROR' else: # response can be only str, all other possible values exhausted return 'PROCESSED: ' + response
I think mypy either already supports this or will support very soon (and the same for Optional)
-- Ivan -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.python.org/pipermail/python-dev/attachments/20160904/b5655f0b/attachment.html>
- Previous message (by thread): [Python-Dev] Please reject or postpone PEP 526
- Next message (by thread): [Python-Dev] Please reject or postpone PEP 526
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]