A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://mail.python.org/pipermail/python-dev/2016-March/143574.html below:

[Python-Dev] PEP 484: a "NewType" constructor

[Python-Dev] PEP 484: a "NewType" constructor [Python-Dev] PEP 484: a "NewType" constructorGuido van Rossum guido at python.org
Mon Mar 21 12:20:16 EDT 2016
Sorry, for PEP feedback it's best to use this issue in the typing
tracker: https://github.com/python/typing/issues/189 (the issue I
linked to was in the mypy tracker).

On Mon, Mar 21, 2016 at 9:15 AM, Guido van Rossum <guido at python.org> wrote:
> Here's one more thing we'd like to add to PEP 484. The description is
> best gleaned from the issue, in particular
> https://github.com/python/mypy/issues/1284#issuecomment-199021176 and
> following (we're going with option (A)).
>
> Really brief example:
>
>   from typing import NewType
>   UserId = NewType('UserId', int)
>
> Now to the type checker UserId is a new type that's compatible with
> int, but converting an int to a UserId requires a special cast form,
> UserId(x). At runtime UserId instances are just ints (not a subclass!)
> and UserId() is a dummy function that just returns its argument.
>
> For use cases see the issue. Also send feedback there please.
>
> --
> --Guido van Rossum (python.org/~guido)



-- 
--Guido van Rossum (python.org/~guido)
More information about the Python-Dev mailing list

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4