Skip to content

*Unary* operators not correctly inherited with NewType(..., float) #2499

@jpgoldberg

Description

@jpgoldberg

Summary

It appears that unary operators were not covered in the fix that resolved #2077, resulting in "unsupported operator" when I uses -thing_of_type_Foo where Foo = NewType("Foo", float).

Note that binary operators do not trigger this error with ty 0.0.11, but the unary - operator does.

How to reproduce

Step 1: Create test file

Create a file like ty_newtype.py with the content:

from typing import NewType

Foo = NewType("Foo", float)

x = float(0.2)
y = -x  # No issues are reported here.

f = Foo(0.2)
g = 2.0 + f  # No issues reported here (since ty 0.0.10)
h = -f  # ty says "Unary operator `-` is not supported ..."

Step 2: Run ty check on iit

# ty check ty_newtype.py
% ty check ty_newtype.py
error[unsupported-operator]: Unary operator `-` is not supported for object of type `Foo`
  --> ty_newtype.py:10:5
   |
 8 | f = Foo(0.2)
 9 | g = 2.0 + f  # No issues reported here (since ty 0.0.10)
10 | h = -f  # ty says "Unary operator `-` is not supported ..."
   |     ^^
   |
info: rule `unsupported-operator` is enabled by default

Found 1 diagnostic

Expected

"Foo = NewType("Foo", float)"

System info

  • ty: ty 0.0.11 (830cb9c 2026-01-09)
  • OS: System Version: macOS 26.1 (25B78)
  • HW: Apple M2 Pro
  • Python: Python 3.14.2

Version

ty 0.0.11 (830cb9c 2026-01-09)

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions