Skip to content

support typing.Self used as attribute (or dataclass field) type #1124

@JoanPuig

Description

@JoanPuig

Summary

The following code:

from dataclasses import dataclass
from typing import Optional, Self


@dataclass(frozen=True)
class MyClass:
    field: Optional[Self] = None


MyClass(MyClass())

reports the following, which I believe should not be an error:

error[invalid-argument-type]: Argument is incorrect
  --> src\main.py:10:9
   |
10 | MyClass(MyClass())
   |         ^^^^^^^^^ Expected `typing.Self | None`, found `MyClass`
   |
info: rule `invalid-argument-type` is enabled by default

Found 1 diagnostic

Version

0.0.1-alpha.20 (f41f00a 2025-09-03)

Metadata

Metadata

Assignees

Labels

typing semanticstyping-module features, spec compliance, etc

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions