-
Code sample in pyright playground from argparse import Namespace
from dataclasses import dataclass
from typing import reveal_type
@dataclass(kw_only=True)
class Application[T]:
args_type: type[T] = Namespace # Type "type[Namespace]" is not assignable to type "type[T@Application]"
class Application1[T]:
args_type: type[T]
def __init__(self, *, args_type: type[T] = Namespace) -> None: # no error
self.args_type = args_type # no error
app = Application()
reveal_type(app)
reveal_type(app.args_type)
app1 = Application1()
reveal_type(app1)
reveal_type(app1.args_type) In this code sample, I get an error when I assign If I rewrite the class to not be a dataclass and I just define my own Despite the error, the type for I do not understand if I'm doing something wrong with the dataclass or I hit some bug in pyright. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
See this issue for an explanation. |
Beta Was this translation helpful? Give feedback.
-
Would you say it's safe to ignore this error without having negative consequences when analysing the code involving this dataclass, or do you think it's better to go with the non-dataclass variant? |
Beta Was this translation helpful? Give feedback.
See this issue for an explanation.