Skip to content

non-init dataclass field overridded by property expected in init #3169

Closed

Description

@DerBiasto

Describe the Bug

I have a dataclass with a non-init field. A subclass overrides that field with a property.

The fact that this is reported as bad override is expected, but in addition pyrefly now expects that field to be present in the dataclasses init again, even though neither with the init=False field nor the property this is required (or even allowed).

It seems like after the bad override, pyrefly expects a dataclass field, but in a different way from the field defined in the parent class.

import dataclasses

@dataclasses.dataclass
class A:
    foo: int = dataclasses.field(init=False)

@dataclasses.dataclass
class B(A):
    pass

    @property
    def foo(self) -> int:  # Class member `B.foo` overrides parent class `A` in an inconsistent manner [bad-override]
        return 1

b = B()  # Missing argument `foo` in function `B.__init__` [missing-argument]
b = B(foo = 2)  # Argument `Literal[2]` is not assignable to parameter `foo` with type `(self: B) -> int` in function `B.__init__` [bad-argument-type]

Sandbox Link

https://pyrefly.org/sandbox/?project=N4IgZglgNgpgziAXKOBDAdgEwEYHsAeAdAA4CeSIEAtsbgE4AuABJqg6gMZSpxzwA66QQAFW7Ljz5xCYzt16CJvJgEFEgppqZhcuREwjpmAXhZs5k%2BIUgwomABSGIDYwDFUUPgEpBI2UqkZcwDFeTgmACF7FS91dC0mYklfeK1hYjpcYhhGUg0tTBgwbV17PigwLyYAWgA%2BAyM4hIS6GAYAVzp4gEYU7CZTKJ90fsH7HVwBpgAmYZAAGhAyVrAoUkIGXCooCgBiJgAFUhW1pjQsPHwmDlx0SABzTrYIW8JBfYBlGBgmAAsGBjEOCIAD0IOWRTWhHo9xBMHQIMwuA4cBBNzuEEedGetxBJToTFQADdUNBUNhYNdbg8ngwXvEsnTbtJBGQGL9btUiTk4PSpvwQABmQjdaYCwQAbRymTocAAuoJ2uhqLRGDBMNVMBBWhw6dypgByTHoegwA2CE0MaqtACO7W16uqAGsYKRqpwOPBwqYDQB3VBdc3oEAAX0WnD1MFc0BgFHOOAIJHIIaAA

(Only applicable for extension issues) IDE Information

No response

Activity

  1. rchen152 commented on Apr 24, 2026

    @rchen152
    Contributor

    It looks like we report bad-override but then use the type anyway, leading to this odd hybrid behavior.

  2. mikeleppane commented on Jun 7, 2026

    @mikeleppane
    Contributor

    I'm working on this.

  3. self-assigned this
    on Jun 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions