MCPcopy Create free account
hub / github.com/astral-sh/ruff / reduce

Method reduce

crates/ruff_python_stdlib/src/open_mode.rs:69–88  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

67 /// Remove any redundant flags from the open mode.
68 #[must_use]
69 pub fn reduce(self) -> Self {
70 let mut open_mode = self;
71
72 // `t` is always redundant.
73 open_mode.remove(Self::TEXT);
74
75 // `U` is always redundant.
76 open_mode.remove(Self::UNIVERSAL_NEWLINES);
77
78 // `r` is redundant, unless `b` or `+` is also set, in which case, we need one of `w`, `a`, `r`, or `x`.
79 if open_mode.intersects(Self::BINARY | Self::PLUS) {
80 if !open_mode.intersects(Self::WRITE | Self::CREATE | Self::APPEND) {
81 open_mode.insert(Self::READ);
82 }
83 } else {
84 open_mode.remove(Self::READ);
85 }
86
87 open_mode
88 }
89}
90
91/// Write the [`OpenMode`] as a string.

Callers 7

from_arg_matchesMethod · 0.80
fromMethod · 0.80
checkFunction · 0.80
extend_with_typeMethod · 0.80
B023.pyFile · 0.80
redundant_open_modesFunction · 0.80

Calls 3

removeMethod · 0.45
intersectsMethod · 0.45
insertMethod · 0.45

Tested by

no test coverage detected