Skip to content

Comments

[pylint] Do not report calls when object type and argument type mismatch, remove custom escape handling logic (PLE1310)#15984

Merged
dylwil3 merged 4 commits intoastral-sh:mainfrom
InSyncWithFoo:PLE1310
Feb 7, 2025
Merged

[pylint] Do not report calls when object type and argument type mismatch, remove custom escape handling logic (PLE1310)#15984
dylwil3 merged 4 commits intoastral-sh:mainfrom
InSyncWithFoo:PLE1310

Conversation

@InSyncWithFoo
Copy link
Contributor

@InSyncWithFoo InSyncWithFoo commented Feb 6, 2025

Summary

Resolves #15968.

Previously, these would be considered violations:

b''.strip('//')
''.lstrip('//', foo = "bar")

...while these are not:

b''.strip(b'//')
''.strip('\\b\\x08')

Ruff will now not report when the types of the object and that of the argument mismatch, or when there are extra arguments.

Test Plan

cargo nextest run and cargo insta test.

@github-actions
Copy link
Contributor

github-actions bot commented Feb 6, 2025

ruff-ecosystem results

Linter (stable)

✅ ecosystem check detected no linter changes.

Linter (preview)

✅ ecosystem check detected no linter changes.

Copy link
Collaborator

@dylwil3 dylwil3 left a comment

Choose a reason for hiding this comment

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

Looks good! Function doc comment needs an update, and I'm confused about why we changed the behavior for Python versions below 3.9.

@MichaReiser MichaReiser added bug Something isn't working rule Implementing or modifying a lint rule labels Feb 6, 2025
Copy link
Collaborator

@dylwil3 dylwil3 left a comment

Choose a reason for hiding this comment

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

Thank you!

@dylwil3 dylwil3 merged commit 19f3424 into astral-sh:main Feb 7, 2025
21 checks passed
@InSyncWithFoo InSyncWithFoo deleted the PLE1310 branch February 7, 2025 20:34
MichaReiser pushed a commit that referenced this pull request Feb 10, 2025
…15985)

## Summary

Follow-up to #15984.

Previously, `PLE1310` would only report when the object is a literal:

```python
'a'.strip('//')  # error

foo = ''
foo.strip('//')  # no error
```

After this change, objects whose type can be inferred to be either `str`
or `bytes` will also be reported in preview.

## Test Plan

`cargo nextest run` and `cargo insta test`.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working rule Implementing or modifying a lint rule

Projects

None yet

Development

Successfully merging this pull request may close these issues.

PLE1310 fails on bytes.strip

3 participants