This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: New type based on int() created with typing.NewType is not consistent
Type: Stage: resolved
Components: Library (Lib) Versions: Python 3.6
process
Status: closed Resolution: rejected
Dependencies: Superseder:
Assigned To: Nosy List: avanov
Priority: normal Keywords:

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:59adminsetgithub: 77351
2018-03-28 15:21:36avanovsetstatus: open -> closed
resolution: rejected
messages: + msg314607

stage: resolved
2018-03-28 15:04:21avanovsetmessages: + msg314604
2018-03-28 14:51:28avanovcreate