Skip to content

Commit 1a65356

Browse files
committed
flat_option -> flatten
by following std::option::Option
1 parent 543104d commit 1a65356

File tree

8 files changed

+17
-17
lines changed

8 files changed

+17
-17
lines changed

vm/src/function.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -404,7 +404,7 @@ pub type OptionalOption<T> = OptionalArg<Option<T>>;
404404

405405
impl<T> OptionalOption<T> {
406406
#[inline]
407-
pub fn flat_option(self) -> Option<T> {
407+
pub fn flatten(self) -> Option<T> {
408408
match self {
409409
Present(Some(value)) => Some(value),
410410
_ => None,

vm/src/obj/objfloat.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -381,7 +381,7 @@ impl PyFloat {
381381

382382
#[pymethod(name = "__round__")]
383383
fn round(&self, ndigits: OptionalOption<PyIntRef>, vm: &VirtualMachine) -> PyResult {
384-
let ndigits = ndigits.flat_option();
384+
let ndigits = ndigits.flatten();
385385
if let Some(ndigits) = ndigits {
386386
let ndigits = ndigits.as_bigint();
387387
if ndigits.is_zero() {

vm/src/obj/objmodule.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ impl PyModuleRef {
5757
vm,
5858
&zelf.as_object().dict().unwrap(),
5959
name.into_object(),
60-
doc.flat_option()
60+
doc.flatten()
6161
.map_or_else(|| vm.get_none(), PyRef::into_object),
6262
);
6363
Ok(zelf)

vm/src/pystr.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ where
251251
FC: Fn(&'a Self, &Self) -> &'a Self,
252252
FD: Fn(&'a Self) -> &'a Self,
253253
{
254-
let chars = chars.flat_option();
254+
let chars = chars.flatten();
255255
match chars {
256256
Some(chars) => func_chars(self, chars.as_ref()),
257257
None => func_default(self),

vm/src/stdlib/io.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ use crate::pyobject::{
2424
use crate::vm::VirtualMachine;
2525

2626
fn byte_count(bytes: OptionalOption<i64>) -> i64 {
27-
bytes.flat_option().unwrap_or(-1 as i64)
27+
bytes.flatten().unwrap_or(-1 as i64)
2828
}
2929
fn os_err(vm: &VirtualMachine, err: io::Error) -> PyBaseExceptionRef {
3030
#[cfg(any(not(target_arch = "wasm32"), target_os = "wasi"))]
@@ -204,7 +204,7 @@ impl PyStringIORef {
204204

205205
fn truncate(self, size: OptionalOption<usize>, vm: &VirtualMachine) -> PyResult<()> {
206206
let mut buffer = self.buffer(vm)?;
207-
let size = size.flat_option().unwrap_or_else(|| buffer.tell() as usize);
207+
let size = size.flatten().unwrap_or_else(|| buffer.tell() as usize);
208208
buffer.cursor.get_mut().truncate(size);
209209
Ok(())
210210
}
@@ -232,7 +232,7 @@ fn string_io_new(
232232
_args: StringIOArgs,
233233
vm: &VirtualMachine,
234234
) -> PyResult<PyStringIORef> {
235-
let flatten = object.flat_option();
235+
let flatten = object.flatten();
236236
let input = flatten.map_or_else(Vec::new, |v| objstr::borrow_value(&v).as_bytes().to_vec());
237237

238238
PyStringIO {
@@ -316,7 +316,7 @@ impl PyBytesIORef {
316316

317317
fn truncate(self, size: OptionalOption<usize>, vm: &VirtualMachine) -> PyResult<()> {
318318
let mut buffer = self.buffer(vm)?;
319-
let size = size.flat_option().unwrap_or_else(|| buffer.tell() as usize);
319+
let size = size.flatten().unwrap_or_else(|| buffer.tell() as usize);
320320
buffer.cursor.get_mut().truncate(size);
321321
Ok(())
322322
}
@@ -411,7 +411,7 @@ fn io_base_checkclosed(
411411
) -> PyResult<()> {
412412
if objbool::boolval(vm, vm.get_attribute(instance, "closed")?)? {
413413
let msg = msg
414-
.flat_option()
414+
.flatten()
415415
.unwrap_or_else(|| vm.new_str("I/O operation on closed file.".to_owned()));
416416
Err(vm.new_exception(vm.ctx.exceptions.value_error.clone(), vec![msg]))
417417
} else {
@@ -426,7 +426,7 @@ fn io_base_checkreadable(
426426
) -> PyResult<()> {
427427
if !objbool::boolval(vm, vm.call_method(&instance, "readable", vec![])?)? {
428428
let msg = msg
429-
.flat_option()
429+
.flatten()
430430
.unwrap_or_else(|| vm.new_str("File or stream is not readable.".to_owned()));
431431
Err(vm.new_exception(vm.ctx.exceptions.value_error.clone(), vec![msg]))
432432
} else {
@@ -441,7 +441,7 @@ fn io_base_checkwritable(
441441
) -> PyResult<()> {
442442
if !objbool::boolval(vm, vm.call_method(&instance, "writable", vec![])?)? {
443443
let msg = msg
444-
.flat_option()
444+
.flatten()
445445
.unwrap_or_else(|| vm.new_str("File or stream is not writable.".to_owned()));
446446
Err(vm.new_exception(vm.ctx.exceptions.value_error.clone(), vec![msg]))
447447
} else {
@@ -456,7 +456,7 @@ fn io_base_checkseekable(
456456
) -> PyResult<()> {
457457
if !objbool::boolval(vm, vm.call_method(&instance, "seekable", vec![])?)? {
458458
let msg = msg
459-
.flat_option()
459+
.flatten()
460460
.unwrap_or_else(|| vm.new_str("File or stream is not seekable.".to_owned()));
461461
Err(vm.new_exception(vm.ctx.exceptions.value_error.clone(), vec![msg]))
462462
} else {
@@ -929,7 +929,7 @@ fn text_io_wrapper_read(
929929
let bytes = vm.call_method(
930930
&raw,
931931
"read",
932-
vec![size.flat_option().unwrap_or_else(|| vm.get_none())],
932+
vec![size.flatten().unwrap_or_else(|| vm.get_none())],
933933
)?;
934934
let bytes = PyBytesLike::try_from_object(vm, bytes)?;
935935
//format bytes into string
@@ -988,7 +988,7 @@ fn text_io_wrapper_readline(
988988
let bytes = vm.call_method(
989989
&raw,
990990
"readline",
991-
vec![size.flat_option().unwrap_or_else(|| vm.get_none())],
991+
vec![size.flatten().unwrap_or_else(|| vm.get_none())],
992992
)?;
993993
let bytes = PyBytesLike::try_from_object(vm, bytes)?;
994994
//format bytes into string

vm/src/stdlib/itertools.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1169,7 +1169,7 @@ mod decl {
11691169
let n = pool.len();
11701170
// If r is not provided, r == n. If provided, r must be a positive integer, or None.
11711171
// If None, it behaves the same as if it was not provided.
1172-
let r = match r.flat_option() {
1172+
let r = match r.flatten() {
11731173
Some(r) => {
11741174
let val = r
11751175
.payload::<PyInt>()

vm/src/stdlib/random.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ mod _random {
8383

8484
#[pymethod]
8585
fn seed(&self, n: OptionalOption<PyIntRef>) {
86-
let new_rng = match n.flat_option() {
86+
let new_rng = match n.flatten() {
8787
None => PyRng::default(),
8888
Some(n) => {
8989
let (_, mut key) = n.as_bigint().abs().to_u32_digits();

vm/src/stdlib/select.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ fn select_select(
113113
timeout: OptionalOption<Either<f64, isize>>,
114114
vm: &VirtualMachine,
115115
) -> PyResult<(PyObjectRef, PyObjectRef, PyObjectRef)> {
116-
let mut timeout = timeout.flat_option().map(|e| match e {
116+
let mut timeout = timeout.flatten().map(|e| match e {
117117
Either::A(f) => f,
118118
Either::B(i) => i as f64,
119119
});

0 commit comments

Comments
 (0)