Skip to content

PLW1514 doesn’t recognize encoding positional argument of codecs.open #18107

@dscorbett

Description

@dscorbett

Summary

unspecified-encoding (PLW1514) fails to recognize the encoding parameter of codecs.open when the argument is passed positionally. encoding is at a different position in codecs.open than in open.

$ cat >plw1514.py <<'# EOF'
import codecs
codecs.open("plw1514.py", "r", "utf-8").close()
# EOF

$ python plw1514.py

$ ruff --isolated check plw1514.py --preview --select PLW1514 --unsafe-fixes --fix
Found 1 error (1 fixed, 0 remaining).

$ cat plw1514.py
import codecs
codecs.open("plw1514.py", "r", "utf-8", encoding="utf-8").close()

$ python plw1514.py
Traceback (most recent call last):
  File "plw1514.py", line 2, in <module>
    codecs.open("plw1514.py", "r", "utf-8", encoding="utf-8").close()
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: open() got multiple values for argument 'encoding'

Version

ruff 0.11.9 (2370297 2025-05-09)

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingfixesRelated to suggested fixes for violationshelp wantedContributions especially welcome

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions