Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Add NewType() to create simple unique types with zero runtime overhead #189

Closed
Assignees
gvanrossum
Milestone
@gvanrossum

Description

@gvanrossum

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:

fromtypingimportNewTypeUserId=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.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions


    [8]ページ先頭

    ©2009-2025 Movatter.jp