UserId = typing.NewType('UserId', str) UserId(1234).lower() # Static type checker says: All good! # Runtime says: AttributeError: 'int' object has no attribute 'lower'