Skip to content

Conversation

@dylwil3
Copy link
Collaborator

@dylwil3 dylwil3 commented Jul 14, 2025

In Python 3.14 the keyword-argument strict was added to map. This PR adds support for this when replacing a starmap-zip call with map in starmap-zip (RUF058).

Progress towards #15506

@dylwil3 dylwil3 added rule Implementing or modifying a lint rule fixes Related to suggested fixes for violations python314 Related to Python 3.14 labels Jul 14, 2025
@dylwil3 dylwil3 mentioned this pull request Jul 14, 2025
1 task
@github-actions
Copy link
Contributor

ruff-ecosystem results

Linter (stable)

✅ ecosystem check detected no linter changes.

Linter (preview)

✅ ecosystem check detected no linter changes.

Comment on lines +71 to 89
let keywords = &iterable_call.arguments.keywords;

match checker.target_version().cmp(&PythonVersion::PY314) {
// Keyword arguments not supported for `map` before Python 3.14
std::cmp::Ordering::Less => {
if !keywords.is_empty() {
return;
}
}
// Only supported keyword argument is `strict` starting in 3.14
std::cmp::Ordering::Equal | std::cmp::Ordering::Greater => {
if keywords.len() > 1 {
return;
}
if keywords.len() == 1 && iterable_call.arguments.find_keyword("strict").is_none() {
return;
}
}
}
Copy link
Member

@MichaReiser MichaReiser Jul 15, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: This reduces the branching by moving most logic into a shared branch

Suggested change
let keywords = &iterable_call.arguments.keywords;
match checker.target_version().cmp(&PythonVersion::PY314) {
// Keyword arguments not supported for `map` before Python 3.14
std::cmp::Ordering::Less => {
if !keywords.is_empty() {
return;
}
}
// Only supported keyword argument is `strict` starting in 3.14
std::cmp::Ordering::Equal | std::cmp::Ordering::Greater => {
if keywords.len() > 1 {
return;
}
if keywords.len() == 1 && iterable_call.arguments.find_keyword("strict").is_none() {
return;
}
}
}
let keywords = &iterable_call.arguments.keywords;
if keywords.len() > 2 {
return;
}
let strict = iterable_call.arguments.find_keyword("strict");
// Only supported keyword argument is `strict` starting in 3.14
if strict.is_some() and checker.target_version() < PythonVersion::PY314 {
return;
}

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think these are equivalent.

I could flatten somewhat but I think the only thing that would be merged would be the case where there is more than one keyword argument supplied.

@dylwil3 dylwil3 merged commit 464144f into astral-sh:main Jul 15, 2025
35 checks passed
dcreager added a commit that referenced this pull request Jul 15, 2025
* main:
  [`pylint`] Extend invalid string character rules to include t-strings (#19355)
  Make TC010 docs example more realistic (#19356)
  Move RDJSON rendering to `ruff_db` (#19293)
  [`flake8-use-pathlib`] Skip single dots for `invalid-pathlib-with-suffix` (`PTH210`) on versions >= 3.14 (#19331)
  [`ruff`] Allow `strict` kwarg when checking for `starmap-zip` (`RUF058`) in Python 3.14+ (#19333)
  [ty] Reduce false positives for `TypedDict` types (#19354)
  [ty] Remove `ConnectionInitializer` (#19353)
  [ty] Use `Type::string_literal()` more (#19352)
  [ty] Add ecosystem-report workflow (#19349)
  [ty] Make use of salsa `Lookup` when interning values (#19347)
  [ty] Sync vendored typeshed stubs (#19345)
  [`pylint`] Make example error out-of-the-box (`PLE2502`) (#19272)
  [`pydoclint`] Fix `SyntaxError` from fixes with line continuations (`D201`, `D202`) (#19246)
dcreager added a commit that referenced this pull request Jul 15, 2025
* dcreager/merge-arguments:
  add types iterator
  add asserting constructor
  debug assert lengths
  remove unused From
  use FromIterator
  [`pylint`] Extend invalid string character rules to include t-strings (#19355)
  Make TC010 docs example more realistic (#19356)
  Move RDJSON rendering to `ruff_db` (#19293)
  [`flake8-use-pathlib`] Skip single dots for `invalid-pathlib-with-suffix` (`PTH210`) on versions >= 3.14 (#19331)
  [`ruff`] Allow `strict` kwarg when checking for `starmap-zip` (`RUF058`) in Python 3.14+ (#19333)
  [ty] Reduce false positives for `TypedDict` types (#19354)
  [ty] Remove `ConnectionInitializer` (#19353)
  [ty] Use `Type::string_literal()` more (#19352)
  [ty] Add ecosystem-report workflow (#19349)
  [ty] Make use of salsa `Lookup` when interning values (#19347)
  [ty] Sync vendored typeshed stubs (#19345)
  [`pylint`] Make example error out-of-the-box (`PLE2502`) (#19272)
  [`pydoclint`] Fix `SyntaxError` from fixes with line continuations (`D201`, `D202`) (#19246)
UnboundVariable pushed a commit to UnboundVariable/ruff that referenced this pull request Jul 15, 2025
…finition

* 'main' of https://github.com/astral-sh/ruff: (39 commits)
  [ty] Sync vendored typeshed stubs (astral-sh#19368)
  Fix typeshed-sync workflow (astral-sh#19367)
  Rework typeshed-sync workflow to also add docstrings for Windows- and MacOS-specific APIs (astral-sh#19360)
  [ty] Allow `-qq` for silent output mode (astral-sh#19366)
  [ty] Allow `-q` short alias for `--quiet` (astral-sh#19364)
  Add shellcheck to pre-commit (astral-sh#19361)
  distinguish references from definitions in `infer_nonlocal`
  [`pycodestyle`] Handle brace escapes for t-strings in logical lines (astral-sh#19358)
  [ty] Combine CallArguments and CallArgumentTypes (astral-sh#19337)
  Move Pylint rendering to `ruff_db` (astral-sh#19340)
  [`pylint`] Extend invalid string character rules to include t-strings (astral-sh#19355)
  Make TC010 docs example more realistic (astral-sh#19356)
  Move RDJSON rendering to `ruff_db` (astral-sh#19293)
  [`flake8-use-pathlib`] Skip single dots for `invalid-pathlib-with-suffix` (`PTH210`) on versions >= 3.14 (astral-sh#19331)
  [`ruff`] Allow `strict` kwarg when checking for `starmap-zip` (`RUF058`) in Python 3.14+ (astral-sh#19333)
  [ty] Reduce false positives for `TypedDict` types (astral-sh#19354)
  [ty] Remove `ConnectionInitializer` (astral-sh#19353)
  [ty] Use `Type::string_literal()` more (astral-sh#19352)
  [ty] Add ecosystem-report workflow (astral-sh#19349)
  [ty] Make use of salsa `Lookup` when interning values (astral-sh#19347)
  ...

# Conflicts:
#	crates/ty_ide/src/goto.rs
#	crates/ty_server/src/server.rs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

fixes Related to suggested fixes for violations python314 Related to Python 3.14 rule Implementing or modifying a lint rule

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants