Describe the bug
In field specifiers of dataclass_transform, we can provide a converter parameter to control the parameter type in __init__. In the following example, we provide a converter=foo where def foo(x: int) -> str, so in __init__ x should be typed int instead of str.
from typing import dataclass_transform
def foo(x: int) -> str: ...
def field(*, converter):
pass
@dataclass_transform(field_specifiers=(field,))
class A:
@classmethod
def __init_subclass__(cls):
pass
class B(A):
x: str = field(converter=foo)
# __init__ signature: B(x: int)
But if we move the converter=foo to a default argument of converter in def field(..), the effect of converter will disappear. This is not consistent with other parameters of field specifiers, as they can all be a default argument instead of being an explicit argument.
from typing import dataclass_transform
def foo(x: int) -> str: ...
def field(*, converter=foo):
pass
@dataclass_transform(field_specifiers=(field,))
class A:
@classmethod
def __init_subclass__(cls):
pass
class B(A):
x: str = field()
# wrong __init__ signature: B(x: str). should be B(x: int) instead
VS Code extension or command-line
ms-python.vscode-pylance 2026.1.1
Describe the bug
In field specifiers of
dataclass_transform, we can provide aconverterparameter to control the parameter type in__init__. In the following example, we provide aconverter=foowheredef foo(x: int) -> str, so in__init__xshould be typedintinstead ofstr.But if we move the
converter=footo a default argument ofconverterindef field(..), the effect ofconverterwill disappear. This is not consistent with other parameters of field specifiers, as they can all be a default argument instead of being an explicit argument.VS Code extension or command-line
ms-python.vscode-pylance 2026.1.1