Skip to content

Do not inherit dataclass defaults from field() overrides without a default - #11665

Open
Henry Su (hsusul) wants to merge 1 commit into
microsoft:mainfrom
hsusul:fix/dataclass-field-override-default
Open

Do not inherit dataclass defaults from field() overrides without a default#11665
Henry Su (hsusul) wants to merge 1 commit into
microsoft:mainfrom
hsusul:fix/dataclass-field-override-default

Conversation

@hsusul

Copy link
Copy Markdown
Contributor

Summary

Test plan

  • npx jest typeEvaluator4.test.ts -t "DataClass" --forceExit (from packages/pyright-internal)
  • Confirm Foo() is reported as missing x when Foo overrides x: int = field() in the language server

…t one.

CPython treats `x: int = field()` as removing the parent default, so the
synthesized __init__ parameter is required. Bare annotations still inherit.

Fixes microsoft#11660
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Signature of dataclass __init__ inferred incorrectly, when overriding a field with a default without specifying a new default

1 participant