@@ -130,7 +130,8 @@ def transform(self) -> None:
130
130
add_method (
131
131
ctx ,
132
132
'__init__' ,
133
- args = [attr .to_argument () for attr in attributes if attr .is_in_init ],
133
+ args = [attr .to_argument () for attr in attributes if attr .is_in_init
134
+ and not self ._is_kw_only_type (attr .type )],
134
135
return_type = NoneType (),
135
136
)
136
137
@@ -257,8 +258,7 @@ def collect_attributes(self) -> Optional[List[DataclassAttribute]]:
257
258
is_init_var = True
258
259
node .type = node_type .args [0 ]
259
260
260
- if (isinstance (node_type , Instance ) and
261
- node_type .type .fullname == 'dataclasses._KW_ONLY_TYPE' ):
261
+ if self ._is_kw_only_type (node_type ):
262
262
kw_only = True
263
263
264
264
has_field_call , field_args = _collect_field_args (stmt .rvalue )
@@ -395,6 +395,15 @@ def _propertize_callables(self, attributes: List[DataclassAttribute]) -> None:
395
395
var ._fullname = info .fullname + '.' + var .name
396
396
info .names [var .name ] = SymbolTableNode (MDEF , var )
397
397
398
+ def _is_kw_only_type (self , node : Optional [Type ]) -> bool :
399
+ """Checks if the type of the node is the KW_ONLY sentinel value."""
400
+ if node is None :
401
+ return False
402
+ node_type = get_proper_type (node )
403
+ if not isinstance (node_type , Instance ):
404
+ return False
405
+ return node_type .type .fullname == 'dataclasses._KW_ONLY_TYPE'
406
+
398
407
399
408
def dataclass_class_maker_callback (ctx : ClassDefContext ) -> None :
400
409
"""Hooks into the class typechecking process to add support for dataclasses.
0 commit comments