Add NewType by ilevkivskyi · Pull Request #226 · python/typing (original) (raw)

I could not follow anything from the Scala ValueType description (no news
there :-).

The explanation "it is the same type with a different name" feels wrong --
if it really was the same name it would be a type alias. In fact it is not
the same type, it has a specific relationship to the original type, which
is exactly that it is a subtype (but not every subtype is a NewType).

I will check with Jukka but unless he has strong objections I am going for
Distinct Type (two words) when we're discussing it in English text, but I
will keep NewType (one function) in code.

On Wed, Jun 1, 2016 at 1:42 AM, Sietse Brouwer notifications@github.com
wrote:

I like @lgautier https://github.com/lgautier's NamedType a lot: to me,
it expresses "this is otherwise the same type, but it has a different name
(and therefore its own meaning)". Also, like he says, it meshes nicely with
namedtuple (and typing.NamedTuple).

How I would read it:

UserID = NamedType('UserID', int) -> This is a type of int named UserID


If NamedType does not make it, what about ValueType?

How I would read it:

UserID = ValueType('UserID', int) -> This is an int with a user ID value
type.

NamedType works better, though.


You are receiving this because you commented.
Reply to this email directly, view it on GitHub
#226 (comment), or mute
the thread
https://github.com/notifications/unsubscribe/ACwrMiamuJVBxyBPxt4bA0yULC0M3MzVks5qHUXcgaJpZM4IoPSY
.

--Guido van Rossum (python.org/~guido)