Skip to content

[New rule] Octal literal for chmod mode bits #18464

@opk12

Description

@opk12

Summary

pathlib.Path('/file').chmod(444) means something different than what it seems, should be chmod(0o444).

Also, chmod of a decimal or hexadecimal literal is most likely unintentional, because it is are hard to read and the standard usage is octal. For example, telling the mode bits from 292 or 0x124 is not straightforward.

A new rule could look for a numeric literal and propose the octal form. There exist stat.S_* constants listed at os.chmod(), but honestly I'm not their fan, as the 3-digit version is cleaner and is standard in the POSIX world.

I don't have experience with the similar functions, but I guess the rule should also cover them.

  • pathlib.Path.lchmod()
  • os.chmod()
  • os.fchmod()
  • os.lchmod()

Docs

Metadata

Metadata

Assignees

Labels

ruleImplementing or modifying a lint rule

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions