[ruff] Exempt NewType calls where the original type is immutable (RUF009) (#15588)
Some checks are pending
CI / cargo fmt (push) Waiting to run
CI / cargo build (release) (push) Waiting to run
CI / cargo build (msrv) (push) Blocked by required conditions
CI / Determine changes (push) Waiting to run
CI / cargo clippy (push) Blocked by required conditions
CI / cargo test (linux) (push) Blocked by required conditions
CI / cargo test (linux, release) (push) Blocked by required conditions
CI / cargo test (windows) (push) Blocked by required conditions
CI / cargo test (wasm) (push) Blocked by required conditions
CI / cargo fuzz build (push) Blocked by required conditions
CI / fuzz parser (push) Blocked by required conditions
CI / test scripts (push) Blocked by required conditions
CI / ecosystem (push) Blocked by required conditions
CI / cargo shear (push) Blocked by required conditions
CI / python package (push) Waiting to run
CI / pre-commit (push) Waiting to run
CI / mkdocs (push) Waiting to run
CI / formatter instabilities and black similarity (push) Blocked by required conditions
CI / test ruff-lsp (push) Blocked by required conditions
CI / benchmarks (push) Blocked by required conditions

## Summary

Resolves #6447.

## Test Plan

`cargo nextest run` and `cargo insta test`.
This commit is contained in:
InSync 2025-01-20 21:44:47 +07:00 committed by GitHub
parent 134fefa945
commit 4cfa355519
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 124 additions and 3 deletions

View file

@ -69,3 +69,31 @@ class IntConversionDescriptor:
@dataclass
class InventoryItem:
quantity_on_hand: IntConversionDescriptor = IntConversionDescriptor(default=100)
# Regression tests for:
# https://github.com/astral-sh/ruff/issues/6447
from typing import NewType
ListOfStrings = NewType("ListOfStrs", list[str])
StringsToInts = NewType("IntsToStrings", dict[str, int])
SpecialString = NewType(name="SpecialString", tp=str)
NegativeInteger = NewType("NegInt", tp=int)
Invalid1 = NewType(*Foo)
Invalid2 = NewType("Invalid2", name=Foo)
Invalid3 = NewType("Invalid3", name=Foo, lorem="ipsum")
@dataclass
class DataclassWithNewTypeFields:
# Errors
a: ListOfStrings = ListOfStrings([])
b: StringsToInts = StringsToInts()
c: Invalid1 = Invalid1()
d: Invalid2 = Invalid2()
e: Invalid3 = Invalid3()
# No errors
e: SpecialString = SpecialString("Lorem ipsum")
f: NegativeInteger = NegativeInteger(-110)