Add NewType#226
Conversation
|
@ilevkivskyi I know you're intent on maintaining the distinction between types and classes, so I think here "class" is the correct choice, no? EDIT: Actually, never mind. I was too focused on how they simulate instantiation. I think there's just something about the name From an introspection POV, an instance of a class with |
|
@JukkaL, what do you think of this design? |
I am intentionally a bit "general" here, see my comment from the issue: Concerning your two other points, the idea here is to be really minimal, to allow minimum overhead. In particular your idea with many base classes is almost equivalent to |
|
Note, see my comment/concern I posted to the corresponding issue. I don't
think this is ripe yet...
|
| NewType helper function | ||
| ----------------------- | ||
|
|
||
| There are also situations, where a programmer might want to avoid logical |
|
|
||
| * Generic, used to create user-defined generic classes | ||
|
|
||
| * Type, used to annotate class objects |
There was a problem hiding this comment.
This and the next one I'll apply right now. They're unrelated to this issue.
There was a problem hiding this comment.
OK, sure, I just posted a link to this PR to python-dev asking for comments.
|
A few things:
|
Good point. I added this in new commit
Here I am not sure. Maybe ad-hoc types? EDIT: replaced by the correct quote |
|
Let's think some more about the name, it feels important. Even if the
function is called NewType.
…--Guido (mobile)
|
|
Appointed types — because they are only nominally distinct. |
|
|
|
|
TypeDef |
|
I like @lgautier's How I would read it:
If
How I would read it:
NamedType works better, though. |
|
I could not follow anything from the Scala ValueType description (no news The explanation "it is the same type with a different name" feels wrong -- I will check with Jukka but unless he has strong objections I am going for On Wed, Jun 1, 2016 at 1:42 AM, Sietse Brouwer notifications@github.com
--Guido van Rossum (python.org/~guido) |
|
I'm going to abandon the "English description" discussion, and merge this as-is. The new function will be called NewType() and in the discussion we'll use "unique type" (like in this PR). |
|
Mypy issue is here: python/mypy#1284 |
Simple minded implementation of
NewType(see #189 and python/mypy#1284 (comment)) plus some tests and a short discussion in the PEP.Also I added
TypeandContextManagerto the list of types provided bytyping.py.