4 ms·
The equivalent in Python is:- from typing import NewType UserId = NewType("UserId", int)
by chaz6 1y ago
The equivalent in Python is:-
from typing import NewType
UserId = NewType("UserId", int)
- sdeframond 1y agoActually, not really. In this case UserId is still an integer, which means any method that takes an integer can also take a UserId. Which means your co-workers are likely to just use integer out of habit. Also, you can still do integer things with them, such as > nonsense = UserId(1) + UserId(2)
- chaz6 1y agoIt will not stop you doing this at runtime of course. It is only intended for type checking.