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)
_______________________________________________
Python-Dev mailing list
Python-Dev@python.org
https://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com

Reply via email to