Pyright: Incorrect "default value" error on certain subclassed dataclasses

Created on 19 Jun 2020  路  2Comments  路  Source: microsoft/pyright

Describe the bug
Subclassed dataclasses incorrectly show the following type error when the parent dataclass contains a field with init=False.

Data class fields without default value cannot appear after data fields with default values

To Reproduce

from dataclasses import dataclass, field


@dataclass
class Parent:
    prop_one: str = field(init=False)

    def __post_init__(self):
        self.prop_one = "test"


@dataclass
class Child(Parent):
    prop_two: str  # <- pyright shows a "default value" type error here


test = Child(prop_two="test")

assert test.prop_one == "test"
assert test.prop_two == "test"

Expected behavior
prop_two on the Child class should not display a type error since prop_one does not contain a default value.

Screenshots or Code
image

VS Code extension or command-line

  • VSCode v1.46.1
  • Pyright v1.1.43
  • Python v.3.7.7
addressed in next version bug

All 2 comments

Thanks for the bug report. This will be fixed in the next version of Pyright.

This is now fixed in version 1.1.45, which I just published.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Afsarsoft picture Afsarsoft  路  3Comments

benjaminsaljooghi picture benjaminsaljooghi  路  3Comments

tamuhey picture tamuhey  路  3Comments

namoshizun picture namoshizun  路  3Comments

dbrattli picture dbrattli  路  3Comments