Skip to content

Conversation

Andrej730
Copy link
Contributor

Summary

Recently stumbled upon type checkers typically not being able to verify kwargs when they're unpacked from just constructed dictionary:

Snippet:

def foo(bar: int):
    return bar + 1


print(foo(**{"bar": 2}))
# No typing errors.
print(foo(**{"bar":2, "baz":22}))

pyright-play
mypy-play

And I've found that PIE804 can be helpful to highlight those cases.
Perhaps a note in PIE804 documentation can help advertise this rule as the one also enchancing type safety.

@ntBre ntBre added the documentation Improvements or additions to documentation label Jun 13, 2025
@ntBre ntBre self-requested a review June 13, 2025 22:34
Copy link
Contributor

github-actions bot commented Jun 13, 2025

ruff-ecosystem results

Linter (stable)

✅ ecosystem check detected no linter changes.

Linter (preview)

✅ ecosystem check detected no linter changes.

@MichaReiser MichaReiser reopened this Jun 19, 2025
@MichaReiser
Copy link
Member

Thank you

@MichaReiser MichaReiser merged commit e180975 into astral-sh:main Jun 20, 2025
67 of 68 checks passed
@Andrej730
Copy link
Contributor Author

🎉🎉
Technically my first few lines of code in .rs I've ever written 😅

@Andrej730 Andrej730 deleted the unnecessary_dict_kwargs_doc branch June 20, 2025 06:46
dcreager added a commit that referenced this pull request Jun 20, 2025
* 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)
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants