A RetroSearch Logo

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

Search Query:

Showing content from https://github.com/python/typing/issues/189 below:

Add NewType() to create simple unique types with zero runtime overhead · Issue #189 · python/typing · GitHub

The description is best gleaned from the following mypy issue: python/mypy#1284 (comment) 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.


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