mirror of
https://github.com/astral-sh/ruff.git
synced 2025-10-03 07:04:53 +00:00
[ty] Do not emit errors if enums or NamedTuples constructed using functional syntax are used in type expressions (#17873)
## Summary This fixes some false positives that showed up in the primer diff for https://github.com/astral-sh/ruff/pull/17832 ## Test Plan new mdtests added that fail with false-positive diagnostics on `main`
This commit is contained in:
parent
fd76d70a31
commit
89424cce5f
2 changed files with 30 additions and 0 deletions
|
@ -0,0 +1,19 @@
|
|||
# Unsupported special types
|
||||
|
||||
We do not understand the functional syntax for creating `NamedTuple`s, `TypedDict`s or `Enum`s yet.
|
||||
But we also do not emit false positives when these are used in type expressions.
|
||||
|
||||
```py
|
||||
import collections
|
||||
import enum
|
||||
import typing
|
||||
|
||||
# TODO: should not error (requires understanding metaclass `__call__`)
|
||||
MyEnum = enum.Enum("MyEnum", ["foo", "bar", "baz"]) # error: [too-many-positional-arguments]
|
||||
|
||||
MyTypedDict = typing.TypedDict("MyTypedDict", {"foo": int})
|
||||
MyNamedTuple1 = typing.NamedTuple("MyNamedTuple1", [("foo", int)])
|
||||
MyNamedTuple2 = collections.namedtuple("MyNamedTuple2", ["foo"])
|
||||
|
||||
def f(a: MyEnum, b: MyTypedDict, c: MyNamedTuple1, d: MyNamedTuple2): ...
|
||||
```
|
Loading…
Add table
Add a link
Reference in a new issue