mirror of
https://github.com/astral-sh/ruff.git
synced 2025-08-04 10:49:50 +00:00
[flake8-use-pathlib
] Implement os-path-getsize
and os-path-get(a|m|c)-time
(PTH202-205
) (#5835)
Reviving https://github.com/astral-sh/ruff/pull/2348 step by step Pt 3. implement detection for: - `os.path.getsize` - `os.path.getmtime` - `os.path.getctime` - `os.path.getatime`
This commit is contained in:
parent
d35cb6942f
commit
4bba0bcab8
19 changed files with 498 additions and 2 deletions
14
crates/ruff/resources/test/fixtures/flake8_use_pathlib/PTH202.py
vendored
Normal file
14
crates/ruff/resources/test/fixtures/flake8_use_pathlib/PTH202.py
vendored
Normal file
|
@ -0,0 +1,14 @@
|
|||
import os.path
|
||||
from pathlib import Path
|
||||
from os.path import getsize
|
||||
|
||||
|
||||
os.path.getsize("filename")
|
||||
os.path.getsize(b"filename")
|
||||
os.path.getsize(Path("filename"))
|
||||
os.path.getsize(__file__)
|
||||
|
||||
getsize("filename")
|
||||
getsize(b"filename")
|
||||
getsize(Path("filename"))
|
||||
getsize(__file__)
|
12
crates/ruff/resources/test/fixtures/flake8_use_pathlib/PTH203.py
vendored
Normal file
12
crates/ruff/resources/test/fixtures/flake8_use_pathlib/PTH203.py
vendored
Normal file
|
@ -0,0 +1,12 @@
|
|||
import os.path
|
||||
from pathlib import Path
|
||||
from os.path import getatime
|
||||
|
||||
os.path.getatime("filename")
|
||||
os.path.getatime(b"filename")
|
||||
os.path.getatime(Path("filename"))
|
||||
|
||||
|
||||
getatime("filename")
|
||||
getatime(b"filename")
|
||||
getatime(Path("filename"))
|
13
crates/ruff/resources/test/fixtures/flake8_use_pathlib/PTH204.py
vendored
Normal file
13
crates/ruff/resources/test/fixtures/flake8_use_pathlib/PTH204.py
vendored
Normal file
|
@ -0,0 +1,13 @@
|
|||
import os.path
|
||||
from pathlib import Path
|
||||
from os.path import getmtime
|
||||
|
||||
|
||||
os.path.getmtime("filename")
|
||||
os.path.getmtime(b"filename")
|
||||
os.path.getmtime(Path("filename"))
|
||||
|
||||
|
||||
getmtime("filename")
|
||||
getmtime(b"filename")
|
||||
getmtime(Path("filename"))
|
12
crates/ruff/resources/test/fixtures/flake8_use_pathlib/PTH205.py
vendored
Normal file
12
crates/ruff/resources/test/fixtures/flake8_use_pathlib/PTH205.py
vendored
Normal file
|
@ -0,0 +1,12 @@
|
|||
import os.path
|
||||
from pathlib import Path
|
||||
from os.path import getctime
|
||||
|
||||
|
||||
os.path.getctime("filename")
|
||||
os.path.getctime(b"filename")
|
||||
os.path.getctime(Path("filename"))
|
||||
|
||||
getctime("filename")
|
||||
getctime(b"filename")
|
||||
getctime(Path("filename"))
|
|
@ -3024,6 +3024,10 @@ where
|
|||
Rule::OsPathSplitext,
|
||||
Rule::BuiltinOpen,
|
||||
Rule::PyPath,
|
||||
Rule::OsPathGetsize,
|
||||
Rule::OsPathGetatime,
|
||||
Rule::OsPathGetmtime,
|
||||
Rule::OsPathGetctime,
|
||||
]) {
|
||||
flake8_use_pathlib::rules::replaceable_by_pathlib(self, func);
|
||||
}
|
||||
|
|
|
@ -749,6 +749,11 @@ pub fn code_to_rule(linter: Linter, code: &str) -> Option<(RuleGroup, Rule)> {
|
|||
(Flake8UsePathlib, "123") => (RuleGroup::Unspecified, rules::flake8_use_pathlib::violations::BuiltinOpen),
|
||||
(Flake8UsePathlib, "124") => (RuleGroup::Unspecified, rules::flake8_use_pathlib::violations::PyPath),
|
||||
(Flake8UsePathlib, "201") => (RuleGroup::Unspecified, rules::flake8_use_pathlib::rules::PathConstructorCurrentDirectory),
|
||||
(Flake8UsePathlib, "202") => (RuleGroup::Unspecified, rules::flake8_use_pathlib::rules::OsPathGetsize),
|
||||
(Flake8UsePathlib, "202") => (RuleGroup::Unspecified, rules::flake8_use_pathlib::rules::OsPathGetsize),
|
||||
(Flake8UsePathlib, "203") => (RuleGroup::Unspecified, rules::flake8_use_pathlib::rules::OsPathGetatime),
|
||||
(Flake8UsePathlib, "204") => (RuleGroup::Unspecified, rules::flake8_use_pathlib::rules::OsPathGetmtime),
|
||||
(Flake8UsePathlib, "205") => (RuleGroup::Unspecified, rules::flake8_use_pathlib::rules::OsPathGetctime),
|
||||
|
||||
// flake8-logging-format
|
||||
(Flake8LoggingFormat, "001") => (RuleGroup::Unspecified, rules::flake8_logging_format::violations::LoggingStringFormat),
|
||||
|
|
|
@ -57,7 +57,10 @@ mod tests {
|
|||
#[test_case(Rule::PyPath, Path::new("py_path_1.py"))]
|
||||
#[test_case(Rule::PyPath, Path::new("py_path_2.py"))]
|
||||
#[test_case(Rule::PathConstructorCurrentDirectory, Path::new("PTH201.py"))]
|
||||
|
||||
#[test_case(Rule::OsPathGetsize, Path::new("PTH202.py"))]
|
||||
#[test_case(Rule::OsPathGetatime, Path::new("PTH203.py"))]
|
||||
#[test_case(Rule::OsPathGetmtime, Path::new("PTH204.py"))]
|
||||
#[test_case(Rule::OsPathGetctime, Path::new("PTH205.py"))]
|
||||
fn rules_pypath(rule_code: Rule, path: &Path) -> Result<()> {
|
||||
let snapshot = format!("{}_{}", rule_code.noqa_code(), path.to_string_lossy());
|
||||
let diagnostics = test_path(
|
||||
|
|
|
@ -1,5 +1,13 @@
|
|||
pub(crate) use os_path_getatime::*;
|
||||
pub(crate) use os_path_getctime::*;
|
||||
pub(crate) use os_path_getmtime::*;
|
||||
pub(crate) use os_path_getsize::*;
|
||||
pub(crate) use path_constructor_current_directory::*;
|
||||
pub(crate) use replaceable_by_pathlib::*;
|
||||
|
||||
mod os_path_getatime;
|
||||
mod os_path_getctime;
|
||||
mod os_path_getmtime;
|
||||
mod os_path_getsize;
|
||||
mod path_constructor_current_directory;
|
||||
mod replaceable_by_pathlib;
|
||||
|
|
|
@ -0,0 +1,43 @@
|
|||
use ruff_diagnostics::Violation;
|
||||
use ruff_macros::{derive_message_formats, violation};
|
||||
|
||||
/// ## What it does
|
||||
/// Checks for uses of `os.path.getatime`.
|
||||
///
|
||||
/// ## Why is this bad?
|
||||
/// `pathlib` offers a high-level API for path manipulation, as compared to
|
||||
/// the lower-level API offered by `os`.
|
||||
///
|
||||
/// When possible, using `Path` object methods such as `Path.stat()` can
|
||||
/// improve readability over the `os` module's counterparts (e.g.,
|
||||
/// `os.path.getsize()`).
|
||||
///
|
||||
/// Note that `os` functions may be preferable if performance is a concern,
|
||||
/// e.g., in hot loops.
|
||||
///
|
||||
/// ## Examples
|
||||
/// ```python
|
||||
/// os.path.getsize(__file__)
|
||||
/// ```
|
||||
///
|
||||
/// Use instead:
|
||||
/// ```python
|
||||
/// Path(__file__).stat().st_size
|
||||
/// ```
|
||||
///
|
||||
/// ## References
|
||||
/// - [Python documentation: `Path.stat`](https://docs.python.org/3/library/pathlib.html#pathlib.Path.stat)
|
||||
/// - [Python documentation: `os.path.getsize`](https://docs.python.org/3/library/os.path.html#os.path.getsize)
|
||||
/// - [PEP 428](https://peps.python.org/pep-0428/)
|
||||
/// - [Correspondence between `os` and `pathlib`](https://docs.python.org/3/library/pathlib.html#correspondence-to-tools-in-the-os-module)
|
||||
/// - [Why you should be using pathlib](https://treyhunner.com/2018/12/why-you-should-be-using-pathlib/)
|
||||
/// - [No really, pathlib is great](https://treyhunner.com/2019/01/no-really-pathlib-is-great/)
|
||||
#[violation]
|
||||
pub struct OsPathGetatime;
|
||||
|
||||
impl Violation for OsPathGetatime {
|
||||
#[derive_message_formats]
|
||||
fn message(&self) -> String {
|
||||
format!("`os.path.getatime` should be replaced by `Path.stat().st_atime`")
|
||||
}
|
||||
}
|
|
@ -0,0 +1,43 @@
|
|||
use ruff_diagnostics::Violation;
|
||||
use ruff_macros::{derive_message_formats, violation};
|
||||
|
||||
/// ## What it does
|
||||
/// Checks for uses of `os.path.getatime`.
|
||||
///
|
||||
/// ## Why is this bad?
|
||||
/// `pathlib` offers a high-level API for path manipulation, as compared to
|
||||
/// the lower-level API offered by `os`.
|
||||
///
|
||||
/// When possible, using `Path` object methods such as `Path.stat()` can
|
||||
/// improve readability over the `os` module's counterparts (e.g.,
|
||||
/// `os.path.getsize()`).
|
||||
///
|
||||
/// Note that `os` functions may be preferable if performance is a concern,
|
||||
/// e.g., in hot loops.
|
||||
///
|
||||
/// ## Examples
|
||||
/// ```python
|
||||
/// os.path.getsize(__file__)
|
||||
/// ```
|
||||
///
|
||||
/// Use instead:
|
||||
/// ```python
|
||||
/// Path(__file__).stat().st_size
|
||||
/// ```
|
||||
///
|
||||
/// ## References
|
||||
/// - [Python documentation: `Path.stat`](https://docs.python.org/3/library/pathlib.html#pathlib.Path.stat)
|
||||
/// - [Python documentation: `os.path.getsize`](https://docs.python.org/3/library/os.path.html#os.path.getsize)
|
||||
/// - [PEP 428](https://peps.python.org/pep-0428/)
|
||||
/// - [Correspondence between `os` and `pathlib`](https://docs.python.org/3/library/pathlib.html#correspondence-to-tools-in-the-os-module)
|
||||
/// - [Why you should be using pathlib](https://treyhunner.com/2018/12/why-you-should-be-using-pathlib/)
|
||||
/// - [No really, pathlib is great](https://treyhunner.com/2019/01/no-really-pathlib-is-great/)
|
||||
#[violation]
|
||||
pub struct OsPathGetctime;
|
||||
|
||||
impl Violation for OsPathGetctime {
|
||||
#[derive_message_formats]
|
||||
fn message(&self) -> String {
|
||||
format!("`os.path.getctime` should be replaced by `Path.stat().st_ctime`")
|
||||
}
|
||||
}
|
|
@ -0,0 +1,43 @@
|
|||
use ruff_diagnostics::Violation;
|
||||
use ruff_macros::{derive_message_formats, violation};
|
||||
|
||||
/// ## What it does
|
||||
/// Checks for uses of `os.path.getatime`.
|
||||
///
|
||||
/// ## Why is this bad?
|
||||
/// `pathlib` offers a high-level API for path manipulation, as compared to
|
||||
/// the lower-level API offered by `os`.
|
||||
///
|
||||
/// When possible, using `Path` object methods such as `Path.stat()` can
|
||||
/// improve readability over the `os` module's counterparts (e.g.,
|
||||
/// `os.path.getsize()`).
|
||||
///
|
||||
/// Note that `os` functions may be preferable if performance is a concern,
|
||||
/// e.g., in hot loops.
|
||||
///
|
||||
/// ## Examples
|
||||
/// ```python
|
||||
/// os.path.getsize(__file__)
|
||||
/// ```
|
||||
///
|
||||
/// Use instead:
|
||||
/// ```python
|
||||
/// Path(__file__).stat().st_size
|
||||
/// ```
|
||||
///
|
||||
/// ## References
|
||||
/// - [Python documentation: `Path.stat`](https://docs.python.org/3/library/pathlib.html#pathlib.Path.stat)
|
||||
/// - [Python documentation: `os.path.getsize`](https://docs.python.org/3/library/os.path.html#os.path.getsize)
|
||||
/// - [PEP 428](https://peps.python.org/pep-0428/)
|
||||
/// - [Correspondence between `os` and `pathlib`](https://docs.python.org/3/library/pathlib.html#correspondence-to-tools-in-the-os-module)
|
||||
/// - [Why you should be using pathlib](https://treyhunner.com/2018/12/why-you-should-be-using-pathlib/)
|
||||
/// - [No really, pathlib is great](https://treyhunner.com/2019/01/no-really-pathlib-is-great/)
|
||||
#[violation]
|
||||
pub struct OsPathGetmtime;
|
||||
|
||||
impl Violation for OsPathGetmtime {
|
||||
#[derive_message_formats]
|
||||
fn message(&self) -> String {
|
||||
format!("`os.path.getmtime` should be replaced by `Path.stat().st_mtime`")
|
||||
}
|
||||
}
|
|
@ -0,0 +1,43 @@
|
|||
use ruff_diagnostics::Violation;
|
||||
use ruff_macros::{derive_message_formats, violation};
|
||||
|
||||
/// ## What it does
|
||||
/// Checks for uses of `os.path.getsize`.
|
||||
///
|
||||
/// ## Why is this bad?
|
||||
/// `pathlib` offers a high-level API for path manipulation, as compared to
|
||||
/// the lower-level API offered by `os`.
|
||||
///
|
||||
/// When possible, using `Path` object methods such as `Path.stat()` can
|
||||
/// improve readability over the `os` module's counterparts (e.g.,
|
||||
/// `os.path.getsize()`).
|
||||
///
|
||||
/// Note that `os` functions may be preferable if performance is a concern,
|
||||
/// e.g., in hot loops.
|
||||
///
|
||||
/// ## Examples
|
||||
/// ```python
|
||||
/// os.path.getsize(__file__)
|
||||
/// ```
|
||||
///
|
||||
/// Use instead:
|
||||
/// ```python
|
||||
/// Path(__file__).stat().st_size
|
||||
/// ```
|
||||
///
|
||||
/// ## References
|
||||
/// - [Python documentation: `Path.stat`](https://docs.python.org/3/library/pathlib.html#pathlib.Path.stat)
|
||||
/// - [Python documentation: `os.path.getsize`](https://docs.python.org/3/library/os.path.html#os.path.getsize)
|
||||
/// - [PEP 428](https://peps.python.org/pep-0428/)
|
||||
/// - [Correspondence between `os` and `pathlib`](https://docs.python.org/3/library/pathlib.html#correspondence-to-tools-in-the-os-module)
|
||||
/// - [Why you should be using pathlib](https://treyhunner.com/2018/12/why-you-should-be-using-pathlib/)
|
||||
/// - [No really, pathlib is great](https://treyhunner.com/2019/01/no-really-pathlib-is-great/)
|
||||
#[violation]
|
||||
pub struct OsPathGetsize;
|
||||
|
||||
impl Violation for OsPathGetsize {
|
||||
#[derive_message_formats]
|
||||
fn message(&self) -> String {
|
||||
format!("`os.path.getsize` should be replaced by `Path.stat().st_size`")
|
||||
}
|
||||
}
|
|
@ -67,7 +67,7 @@ pub(crate) fn path_constructor_current_directory(checker: &mut Checker, expr: &E
|
|||
let [Expr::Constant(ExprConstant {
|
||||
value: Constant::Str(value),
|
||||
kind: _,
|
||||
range
|
||||
range,
|
||||
})] = args.as_slice()
|
||||
else {
|
||||
return;
|
||||
|
|
|
@ -4,6 +4,9 @@ use ruff_diagnostics::{Diagnostic, DiagnosticKind};
|
|||
|
||||
use crate::checkers::ast::Checker;
|
||||
use crate::registry::AsRule;
|
||||
use crate::rules::flake8_use_pathlib::rules::{
|
||||
OsPathGetatime, OsPathGetctime, OsPathGetmtime, OsPathGetsize,
|
||||
};
|
||||
use crate::rules::flake8_use_pathlib::violations::{
|
||||
BuiltinOpen, OsChmod, OsGetcwd, OsMakedirs, OsMkdir, OsPathAbspath, OsPathBasename,
|
||||
OsPathDirname, OsPathExists, OsPathExpanduser, OsPathIsabs, OsPathIsdir, OsPathIsfile,
|
||||
|
@ -41,6 +44,14 @@ pub(crate) fn replaceable_by_pathlib(checker: &mut Checker, expr: &Expr) {
|
|||
["os", "path", "dirname"] => Some(OsPathDirname.into()),
|
||||
["os", "path", "samefile"] => Some(OsPathSamefile.into()),
|
||||
["os", "path", "splitext"] => Some(OsPathSplitext.into()),
|
||||
// PTH202
|
||||
["os", "path", "getsize"] => Some(OsPathGetsize.into()),
|
||||
// PTH203
|
||||
["os", "path", "getatime"] => Some(OsPathGetatime.into()),
|
||||
// PTH204
|
||||
["os", "path", "getmtime"] => Some(OsPathGetmtime.into()),
|
||||
// PTH205
|
||||
["os", "path", "getctime"] => Some(OsPathGetctime.into()),
|
||||
["", "open"] => Some(BuiltinOpen.into()),
|
||||
["py", "path", "local"] => Some(PyPath.into()),
|
||||
// Python 3.9+
|
||||
|
|
|
@ -0,0 +1,76 @@
|
|||
---
|
||||
source: crates/ruff/src/rules/flake8_use_pathlib/mod.rs
|
||||
---
|
||||
PTH202.py:6:1: PTH202 `os.path.getsize` should be replaced by `Path.stat().st_size`
|
||||
|
|
||||
6 | os.path.getsize("filename")
|
||||
| ^^^^^^^^^^^^^^^ PTH202
|
||||
7 | os.path.getsize(b"filename")
|
||||
8 | os.path.getsize(Path("filename"))
|
||||
|
|
||||
|
||||
PTH202.py:7:1: PTH202 `os.path.getsize` should be replaced by `Path.stat().st_size`
|
||||
|
|
||||
6 | os.path.getsize("filename")
|
||||
7 | os.path.getsize(b"filename")
|
||||
| ^^^^^^^^^^^^^^^ PTH202
|
||||
8 | os.path.getsize(Path("filename"))
|
||||
9 | os.path.getsize(__file__)
|
||||
|
|
||||
|
||||
PTH202.py:8:1: PTH202 `os.path.getsize` should be replaced by `Path.stat().st_size`
|
||||
|
|
||||
6 | os.path.getsize("filename")
|
||||
7 | os.path.getsize(b"filename")
|
||||
8 | os.path.getsize(Path("filename"))
|
||||
| ^^^^^^^^^^^^^^^ PTH202
|
||||
9 | os.path.getsize(__file__)
|
||||
|
|
||||
|
||||
PTH202.py:9:1: PTH202 `os.path.getsize` should be replaced by `Path.stat().st_size`
|
||||
|
|
||||
7 | os.path.getsize(b"filename")
|
||||
8 | os.path.getsize(Path("filename"))
|
||||
9 | os.path.getsize(__file__)
|
||||
| ^^^^^^^^^^^^^^^ PTH202
|
||||
10 |
|
||||
11 | getsize("filename")
|
||||
|
|
||||
|
||||
PTH202.py:11:1: PTH202 `os.path.getsize` should be replaced by `Path.stat().st_size`
|
||||
|
|
||||
9 | os.path.getsize(__file__)
|
||||
10 |
|
||||
11 | getsize("filename")
|
||||
| ^^^^^^^ PTH202
|
||||
12 | getsize(b"filename")
|
||||
13 | getsize(Path("filename"))
|
||||
|
|
||||
|
||||
PTH202.py:12:1: PTH202 `os.path.getsize` should be replaced by `Path.stat().st_size`
|
||||
|
|
||||
11 | getsize("filename")
|
||||
12 | getsize(b"filename")
|
||||
| ^^^^^^^ PTH202
|
||||
13 | getsize(Path("filename"))
|
||||
14 | getsize(__file__)
|
||||
|
|
||||
|
||||
PTH202.py:13:1: PTH202 `os.path.getsize` should be replaced by `Path.stat().st_size`
|
||||
|
|
||||
11 | getsize("filename")
|
||||
12 | getsize(b"filename")
|
||||
13 | getsize(Path("filename"))
|
||||
| ^^^^^^^ PTH202
|
||||
14 | getsize(__file__)
|
||||
|
|
||||
|
||||
PTH202.py:14:1: PTH202 `os.path.getsize` should be replaced by `Path.stat().st_size`
|
||||
|
|
||||
12 | getsize(b"filename")
|
||||
13 | getsize(Path("filename"))
|
||||
14 | getsize(__file__)
|
||||
| ^^^^^^^ PTH202
|
||||
|
|
||||
|
||||
|
|
@ -0,0 +1,54 @@
|
|||
---
|
||||
source: crates/ruff/src/rules/flake8_use_pathlib/mod.rs
|
||||
---
|
||||
PTH203.py:5:1: PTH203 `os.path.getatime` should be replaced by `Path.stat().st_atime`
|
||||
|
|
||||
3 | from os.path import getatime
|
||||
4 |
|
||||
5 | os.path.getatime("filename")
|
||||
| ^^^^^^^^^^^^^^^^ PTH203
|
||||
6 | os.path.getatime(b"filename")
|
||||
7 | os.path.getatime(Path("filename"))
|
||||
|
|
||||
|
||||
PTH203.py:6:1: PTH203 `os.path.getatime` should be replaced by `Path.stat().st_atime`
|
||||
|
|
||||
5 | os.path.getatime("filename")
|
||||
6 | os.path.getatime(b"filename")
|
||||
| ^^^^^^^^^^^^^^^^ PTH203
|
||||
7 | os.path.getatime(Path("filename"))
|
||||
|
|
||||
|
||||
PTH203.py:7:1: PTH203 `os.path.getatime` should be replaced by `Path.stat().st_atime`
|
||||
|
|
||||
5 | os.path.getatime("filename")
|
||||
6 | os.path.getatime(b"filename")
|
||||
7 | os.path.getatime(Path("filename"))
|
||||
| ^^^^^^^^^^^^^^^^ PTH203
|
||||
|
|
||||
|
||||
PTH203.py:10:1: PTH203 `os.path.getatime` should be replaced by `Path.stat().st_atime`
|
||||
|
|
||||
10 | getatime("filename")
|
||||
| ^^^^^^^^ PTH203
|
||||
11 | getatime(b"filename")
|
||||
12 | getatime(Path("filename"))
|
||||
|
|
||||
|
||||
PTH203.py:11:1: PTH203 `os.path.getatime` should be replaced by `Path.stat().st_atime`
|
||||
|
|
||||
10 | getatime("filename")
|
||||
11 | getatime(b"filename")
|
||||
| ^^^^^^^^ PTH203
|
||||
12 | getatime(Path("filename"))
|
||||
|
|
||||
|
||||
PTH203.py:12:1: PTH203 `os.path.getatime` should be replaced by `Path.stat().st_atime`
|
||||
|
|
||||
10 | getatime("filename")
|
||||
11 | getatime(b"filename")
|
||||
12 | getatime(Path("filename"))
|
||||
| ^^^^^^^^ PTH203
|
||||
|
|
||||
|
||||
|
|
@ -0,0 +1,52 @@
|
|||
---
|
||||
source: crates/ruff/src/rules/flake8_use_pathlib/mod.rs
|
||||
---
|
||||
PTH204.py:6:1: PTH204 `os.path.getmtime` should be replaced by `Path.stat().st_mtime`
|
||||
|
|
||||
6 | os.path.getmtime("filename")
|
||||
| ^^^^^^^^^^^^^^^^ PTH204
|
||||
7 | os.path.getmtime(b"filename")
|
||||
8 | os.path.getmtime(Path("filename"))
|
||||
|
|
||||
|
||||
PTH204.py:7:1: PTH204 `os.path.getmtime` should be replaced by `Path.stat().st_mtime`
|
||||
|
|
||||
6 | os.path.getmtime("filename")
|
||||
7 | os.path.getmtime(b"filename")
|
||||
| ^^^^^^^^^^^^^^^^ PTH204
|
||||
8 | os.path.getmtime(Path("filename"))
|
||||
|
|
||||
|
||||
PTH204.py:8:1: PTH204 `os.path.getmtime` should be replaced by `Path.stat().st_mtime`
|
||||
|
|
||||
6 | os.path.getmtime("filename")
|
||||
7 | os.path.getmtime(b"filename")
|
||||
8 | os.path.getmtime(Path("filename"))
|
||||
| ^^^^^^^^^^^^^^^^ PTH204
|
||||
|
|
||||
|
||||
PTH204.py:11:1: PTH204 `os.path.getmtime` should be replaced by `Path.stat().st_mtime`
|
||||
|
|
||||
11 | getmtime("filename")
|
||||
| ^^^^^^^^ PTH204
|
||||
12 | getmtime(b"filename")
|
||||
13 | getmtime(Path("filename"))
|
||||
|
|
||||
|
||||
PTH204.py:12:1: PTH204 `os.path.getmtime` should be replaced by `Path.stat().st_mtime`
|
||||
|
|
||||
11 | getmtime("filename")
|
||||
12 | getmtime(b"filename")
|
||||
| ^^^^^^^^ PTH204
|
||||
13 | getmtime(Path("filename"))
|
||||
|
|
||||
|
||||
PTH204.py:13:1: PTH204 `os.path.getmtime` should be replaced by `Path.stat().st_mtime`
|
||||
|
|
||||
11 | getmtime("filename")
|
||||
12 | getmtime(b"filename")
|
||||
13 | getmtime(Path("filename"))
|
||||
| ^^^^^^^^ PTH204
|
||||
|
|
||||
|
||||
|
|
@ -0,0 +1,56 @@
|
|||
---
|
||||
source: crates/ruff/src/rules/flake8_use_pathlib/mod.rs
|
||||
---
|
||||
PTH205.py:6:1: PTH205 `os.path.getctime` should be replaced by `Path.stat().st_ctime`
|
||||
|
|
||||
6 | os.path.getctime("filename")
|
||||
| ^^^^^^^^^^^^^^^^ PTH205
|
||||
7 | os.path.getctime(b"filename")
|
||||
8 | os.path.getctime(Path("filename"))
|
||||
|
|
||||
|
||||
PTH205.py:7:1: PTH205 `os.path.getctime` should be replaced by `Path.stat().st_ctime`
|
||||
|
|
||||
6 | os.path.getctime("filename")
|
||||
7 | os.path.getctime(b"filename")
|
||||
| ^^^^^^^^^^^^^^^^ PTH205
|
||||
8 | os.path.getctime(Path("filename"))
|
||||
|
|
||||
|
||||
PTH205.py:8:1: PTH205 `os.path.getctime` should be replaced by `Path.stat().st_ctime`
|
||||
|
|
||||
6 | os.path.getctime("filename")
|
||||
7 | os.path.getctime(b"filename")
|
||||
8 | os.path.getctime(Path("filename"))
|
||||
| ^^^^^^^^^^^^^^^^ PTH205
|
||||
9 |
|
||||
10 | getctime("filename")
|
||||
|
|
||||
|
||||
PTH205.py:10:1: PTH205 `os.path.getctime` should be replaced by `Path.stat().st_ctime`
|
||||
|
|
||||
8 | os.path.getctime(Path("filename"))
|
||||
9 |
|
||||
10 | getctime("filename")
|
||||
| ^^^^^^^^ PTH205
|
||||
11 | getctime(b"filename")
|
||||
12 | getctime(Path("filename"))
|
||||
|
|
||||
|
||||
PTH205.py:11:1: PTH205 `os.path.getctime` should be replaced by `Path.stat().st_ctime`
|
||||
|
|
||||
10 | getctime("filename")
|
||||
11 | getctime(b"filename")
|
||||
| ^^^^^^^^ PTH205
|
||||
12 | getctime(Path("filename"))
|
||||
|
|
||||
|
||||
PTH205.py:12:1: PTH205 `os.path.getctime` should be replaced by `Path.stat().st_ctime`
|
||||
|
|
||||
10 | getctime("filename")
|
||||
11 | getctime(b"filename")
|
||||
12 | getctime(Path("filename"))
|
||||
| ^^^^^^^^ PTH205
|
||||
|
|
||||
|
||||
|
4
ruff.schema.json
generated
4
ruff.schema.json
generated
|
@ -2329,6 +2329,10 @@
|
|||
"PTH2",
|
||||
"PTH20",
|
||||
"PTH201",
|
||||
"PTH202",
|
||||
"PTH203",
|
||||
"PTH204",
|
||||
"PTH205",
|
||||
"PYI",
|
||||
"PYI0",
|
||||
"PYI00",
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue