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

## Summary

Resolves #15968.

Previously, these would be considered violations:

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

...while these are not:

```python
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`.
This commit is contained in:
InSync 2025-02-08 03:31:07 +07:00 committed by GitHub
parent d4a5772d96
commit 19f3424a1a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 137 additions and 47 deletions

View file

@ -64,10 +64,42 @@ u''.strip('http://')
u''.lstrip('http://')
# PLE1310
b''.rstrip('http://')
b''.rstrip(b'http://')
# OK
''.strip('Hi')
# OK
''.strip()
### https://github.com/astral-sh/ruff/issues/15968
# Errors: Multiple backslashes
''.strip('\\b\\x09')
''.strip(r'\b\x09')
''.strip('\\\x5C')
# OK: Different types
b"".strip("//")
"".strip(b"//")
# OK: Escapes
'\\test'.strip('\\')
# OK: Extra/missing arguments
"".strip("//", foo)
b"".lstrip(b"//", foo = "bar")
"".rstrip()
# OK: Not literals
foo: str = ""; bar: bytes = b""
"".strip(foo)
b"".strip(bar)
# False negative
foo.rstrip("//")
bar.lstrip(b"//")
# OK: Not `.[lr]?strip`
"".mobius_strip("")