Issue 33170: New type based on int() created with typing.NewType is not consistent (original) (raw)
Issue33170
Created on 2018-03-28 14:51 by avanov, last changed 2022-04-11 14:58 by admin. This issue is now closed.
Messages (3) | ||
---|---|---|
msg314598 - (view) | Author: Maxim Avanov (avanov) | Date: 2018-03-28 14:51 |
From my understanding of the docs section on new types, https://docs.python.org/3/library/typing.html#newtype the new type based on int() should just pass the value into the base constructor. However, ``` PercentDiscount = NewType('PercentDiscount', int) >>> PercentDiscount(50) == int(50) True >>> int('50') == int(50) True >>> PercentDiscount('50') == PercentDiscount(50) False ``` | ||
msg314604 - (view) | Author: Maxim Avanov (avanov) | Date: 2018-03-28 15:04 |
Logically, I would expect it to behave similarly to ``` >>> class PercentDiscount(int): pass >>> PercentDiscount('50') == PercentDiscount(50) True ``` | ||
msg314607 - (view) | Author: Maxim Avanov (avanov) | Date: 2018-03-28 15:21 |
Ok, after further reading, I see that NewType creates an identity stub. |
History | |||
---|---|---|---|
Date | User | Action | Args |
2022-04-11 14:58:59 | admin | set | github: 77351 |
2018-03-28 15:21:36 | avanov | set | status: open -> closedresolution: rejectedmessages: + stage: resolved |
2018-03-28 15:04:21 | avanov | set | messages: + |
2018-03-28 14:51:28 | avanov | create |