ruff icon indicating copy to clipboard operation
ruff copied to clipboard

False positive PLC0132 for NewType wrapped in Annotated

Open minmax opened this issue 1 year ago • 2 comments

Ruff 0.3.5 false positive PLC0132 for NewType wrapped in Annotated

MyIds = Annotated[NewType("WrongName", str), int] # PLC0132 doesn't work

MyId = NewType("Id", str) # NewType` name `Id` does not match assigned variable name `MyId` PLC0132

Keywords: Annotated, NewType, PLC0132

minmax avatar Apr 08 '24 22:04 minmax

Thanks!

charliermarsh avatar Apr 08 '24 23:04 charliermarsh

@erictraut say's that it is not a bug, so maybe this issuer need to be closed without fix/code.

Pyright is working correctly here. When you wrap a NewType with Annotated, the resulting object is no longer a NewType. It's a type alias. It's name does not need to match that of the (anonymous) NewType that was created.

Related task in pyright repo: 7645

minmax avatar Apr 09 '24 11:04 minmax

Ah ok, thanks for following up!

charliermarsh avatar Apr 11 '24 02:04 charliermarsh