[ty] Report when a dataclass contains more than one KW_ONLY field#18731
[ty] Report when a dataclass contains more than one KW_ONLY field#18731carljm merged 4 commits intoastral-sh:mainfrom
KW_ONLY field#18731Conversation
|
bab19ad to
c93c828
Compare
|
Currently the diagnostic doesn't look quite as nice as I want it to be. I think it should show all offending fields in subdiagnostics, but
@dataclass
class C:
a: KW_ONLY
a: KW_ONLY # Same name |
That doesn't cause a |
...dtest/snapshots/dataclasses.md_-_Dataclasses_-_`dataclasses.KW_ONLY…_(dd1b8f2f71487f16).snap
Outdated
Show resolved
Hide resolved
...dtest/snapshots/dataclasses.md_-_Dataclasses_-_`dataclasses.KW_ONLY…_(dd1b8f2f71487f16).snap
Outdated
Show resolved
Hide resolved
abhijeetbodas2001
left a comment
There was a problem hiding this comment.
Thanks! For me, this diff is also helpful as a tutorial on how to add a new diagnostic :)
Another idea for a lint rule here could be to recommend using |
* main: (21 commits) [`flake8-logging`] Avoid false positive for `exc_info=True` outside `logger.exception` (`LOG014`) (#18737) [`flake8-pie`] Small docs fix to `PIE794` (#18829) [`pylint`] Ignore __init__.py files in (PLC0414) (#18400) Avoid generating diagnostics with per-file ignores (#18801) [`flake8-simplify`] Fix false negatives for shadowed bindings (`SIM910`, `SIM911`) (#18794) [ty] Fix panics when pulling types for `ClassVar` or `Final` parameterized with >1 argument (#18824) [`pylint`] add fix safety section (`PLR1714`) (#18415) [Perflint] Small docs improvement to `PERF401` (#18786) [`pylint`] Avoid flattening nested `min`/`max` when outer call has single argument (`PLW3301`) (#16885) [`ruff`] Added `cls.__dict__.get('__annotations__')` check (`RUF063`) (#18233) [ty] Use `HashTable` in `PlaceTable` (#18819) docs: Correct collections-named-tuple example to use PascalCase assignment (#16884) [ty] ecosystem-analyzer workflow (#18719) [ty] Add support for `@staticmethod`s (#18809) unnecessary_dict_kwargs doc - a note on type checking benefits (#18666) [`flake8-pytest-style`] Mark autofix for `PT001` and `PT023` as unsafe if there's comments in the decorator (#18792) [ty] Surface matched overload diagnostic directly (#18452) [ty] Report when a dataclass contains more than one `KW_ONLY` field (#18731) [`flake8-pie`] Add fix safety section to `PIE794` (#18802) [`pycodestyle`] Add fix safety section to `W291` and `W293` (#18800) ...
Summary
Part of #111.
After this change, dataclasses with two or more
KW_ONLYfield will be reported as invalid. The duplicate fields will simply be ignored when computing__init__'s signature.Test Plan
Markdown tests.