Skip to content

PTH123 suggest to use pathlib.Path.open() which does not implement opener #7620

@M5oul

Description

@M5oul

Issue

In case an opener is used into open() function, for creating a file with certain permission for instance, ruff PTH123 suggests to use pathlib.Path.open() which does not implement the opener.

import os
dir_fd = os.open('somedir', os.O_RDONLY)
def opener(path, flags):
    return os.open(path, flags, dir_fd=dir_fd)

with open('spamspam.txt', 'w', opener=opener) as f:
    print('This will be written to somedir/spamspam.txt', file=f)
  • ruff version range: v0.0.276 - v0.0.291

Reference

Solution

  • Ruff can stop reporting it in case an opener is defined
  • Using # noqa: PTH123

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions