no-nominal-rebrand
Preserve NewType identity across constructor calls.
Why
NewType returns its argument unchanged at runtime. Converting directly between nominal types with a shared carrier can pass type checking and cross a domain boundary without validation.
Fix
Keep the declared nominal type, or validate and translate the value at the domain boundary.
Examples
from typing import NewType
UserId = NewType("UserId", str)OrgId = NewType("OrgId", str)
def user_key(organization: OrgId) -> UserId: return UserId(organization)from typing import NewType
UserId = NewType("UserId", str)OrgId = NewType("OrgId", str)
def user_key(organization: str) -> UserId: return UserId(organization)