Skip to content

Commit 2fce2cc

Browse files
committed
WIP: try to fix linting
1 parent 99460bf commit 2fce2cc

File tree

7 files changed

+17
-82
lines changed

7 files changed

+17
-82
lines changed

benches/main.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,6 @@ fn list_error_json(bench: &mut Bencher) {
151151
Ok(_) => panic!("unexpectedly valid"),
152152
Err(e) => {
153153
let v = e.value(py);
154-
// println!("error: {}", v.to_string());
155154
assert_eq!(v.getattr("title").unwrap().to_string(), "list[int]");
156155
let error_count: i64 = v.call_method0("error_count").unwrap().extract().unwrap();
157156
assert_eq!(error_count, 100);
@@ -184,7 +183,6 @@ fn list_error_python_input(py: Python<'_>) -> (SchemaValidator, PyObject) {
184183
Ok(_) => panic!("unexpectedly valid"),
185184
Err(e) => {
186185
let v = e.value(py);
187-
// println!("error: {}", v.to_string());
188186
assert_eq!(v.getattr("title").unwrap().to_string(), "list[int]");
189187
let error_count: i64 = v.call_method0("error_count").unwrap().extract().unwrap();
190188
assert_eq!(error_count, 100);
@@ -357,7 +355,6 @@ fn dict_value_error(bench: &mut Bencher) {
357355
Ok(_) => panic!("unexpectedly valid"),
358356
Err(e) => {
359357
let v = e.value(py);
360-
// println!("error: {}", v.to_string());
361358
assert_eq!(v.getattr("title").unwrap().to_string(), "dict[str,constrained-int]");
362359
let error_count: i64 = v.call_method0("error_count").unwrap().extract().unwrap();
363360
assert_eq!(error_count, 100);
@@ -484,7 +481,6 @@ fn typed_dict_deep_error(bench: &mut Bencher) {
484481
Ok(_) => panic!("unexpectedly valid"),
485482
Err(e) => {
486483
let v = e.value(py);
487-
// println!("error: {}", v.to_string());
488484
assert_eq!(v.getattr("title").unwrap().to_string(), "typed-dict");
489485
let error_count: i64 = v.call_method0("error_count").unwrap().extract().unwrap();
490486
assert_eq!(error_count, 1);

src/input/input_python.rs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ use super::{
4949
Input,
5050
};
5151

52-
static FRACTION_TYPE: PyOnceLock<Py<PyType>> = PyOnceLock::new();
52+
5353

5454
pub(crate) fn downcast_python_input<'py, T: PyTypeCheck>(input: &(impl Input<'py> + ?Sized)) -> Option<&Bound<'py, T>> {
5555
input.as_python().and_then(|any| any.downcast::<T>().ok())
@@ -59,7 +59,6 @@ pub(crate) fn input_as_python_instance<'a, 'py>(
5959
input: &'a (impl Input<'py> + ?Sized),
6060
class: &Bound<'py, PyType>,
6161
) -> Option<&'a Bound<'py, PyAny>> {
62-
println!("input_as_python_instance: class={:?}", class);
6362
input.as_python().filter(|any| any.is_instance(class).unwrap_or(false))
6463
}
6564

@@ -158,7 +157,6 @@ impl<'py> Input<'py> for Bound<'py, PyAny> {
158157
strict: bool,
159158
coerce_numbers_to_str: bool,
160159
) -> ValResult<ValidationMatch<EitherString<'_, 'py>>> {
161-
println!("[RUST]: Call validate_str with {:?}, and strict {:?}", self, strict);
162160
if let Ok(py_str) = self.downcast_exact::<PyString>() {
163161
return Ok(ValidationMatch::exact(py_str.clone().into()));
164162
} else if let Ok(py_str) = self.downcast::<PyString>() {
@@ -275,7 +273,6 @@ impl<'py> Input<'py> for Bound<'py, PyAny> {
275273

276274
'lax: {
277275
if !strict {
278-
println!("[RUST]: validate_int lax path for {:?}", self);
279276
return if let Some(s) = maybe_as_string(self, ErrorTypeDefaults::IntParsing)? {
280277
str_as_int(self, s)
281278
} else if self.is_exact_instance_of::<PyFloat>() {
@@ -342,7 +339,6 @@ impl<'py> Input<'py> for Bound<'py, PyAny> {
342339
}
343340

344341
fn validate_fraction(&self, strict: bool, py: Python<'py>) -> ValMatch<Bound<'py, PyAny>> {
345-
println!("[RUST]: Call validate_fraction with {:?}, and strict {:?}", self, strict);
346342
let fraction_type = get_fraction_type(py);
347343

348344
// Fast path for existing decimal objects
@@ -383,7 +379,6 @@ impl<'py> Input<'py> for Bound<'py, PyAny> {
383379
}
384380

385381
fn validate_decimal(&self, strict: bool, py: Python<'py>) -> ValMatch<Bound<'py, PyAny>> {
386-
println!("[RUST]: Call validate_decimal with {:?}, and strict {:?}", self, strict);
387382
let decimal_type = get_decimal_type(py);
388383

389384
// Fast path for existing decimal objects

src/serializers/infer.rs

Lines changed: 6 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -136,16 +136,8 @@ pub(crate) fn infer_to_python_known(
136136
}
137137
v.into_py_any(py)?
138138
}
139-
ObType::Decimal => {
140-
// todo: delete before PR ready
141-
println!("[RUST] infer_to_python_known - SerMode::Json - serializing ObType::Decimal");
142-
value.to_string().into_py_any(py)?
143-
},
144-
ObType::Fraction => {
145-
// todo: delete before PR ready
146-
println!("[RUST] infer_to_python_known - SerMode::Json - serializing ObType::Fraction");
147-
value.to_string().into_py_any(py)?
148-
},
139+
ObType::Decimal => value.to_string().into_py_any(py)?,
140+
ObType::Fraction => value.to_string().into_py_any(py)?,
149141
ObType::StrSubclass => PyString::new(py, value.downcast::<PyString>()?.to_str()?).into(),
150142
ObType::Bytes => extra
151143
.config
@@ -439,16 +431,8 @@ pub(crate) fn infer_serialize_known<S: Serializer>(
439431
let v = value.extract::<f64>().map_err(py_err_se_err)?;
440432
type_serializers::float::serialize_f64(v, serializer, extra.config.inf_nan_mode)
441433
}
442-
ObType::Decimal => {
443-
// todo: delete before PR ready
444-
println!("[RUST] infer_serialize_known - serializing ObType::Decimal");
445-
value.to_string().serialize(serializer)
446-
},
447-
ObType::Fraction => {
448-
// todo: delete before PR ready
449-
println!("[RUST] infer_serialize_known - serializing ObType::Fraction");
450-
value.to_string().serialize(serializer)
451-
},
434+
ObType::Decimal => value.to_string().serialize(serializer),
435+
ObType::Fraction => value.to_string().serialize(serializer),
452436
ObType::Str | ObType::StrSubclass => {
453437
let py_str = value.downcast::<PyString>().map_err(py_err_se_err)?;
454438
super::type_serializers::string::serialize_py_str(py_str, serializer)
@@ -630,16 +614,8 @@ pub(crate) fn infer_json_key_known<'a>(
630614
super::type_serializers::simple::to_str_json_key(key)
631615
}
632616
}
633-
ObType::Decimal => {
634-
// todo: delete before PR ready
635-
println!("[RUST] infer_json_key_known - converting ObType::Decimal to json key");
636-
Ok(Cow::Owned(key.to_string()))
637-
},
638-
ObType::Fraction => {
639-
// todo: delete before PR ready
640-
println!("[RUST] infer_json_key_known - converting ObType::Fraction to json key");
641-
Ok(Cow::Owned(key.to_string()))
642-
},
617+
ObType::Decimal => Ok(Cow::Owned(key.to_string())),
618+
ObType::Fraction => Ok(Cow::Owned(key.to_string())),
643619
ObType::Bool => super::type_serializers::simple::bool_json_key(key),
644620
ObType::Str | ObType::StrSubclass => key.downcast::<PyString>()?.to_cow(),
645621
ObType::Bytes => extra

src/serializers/ob_type.rs

Lines changed: 4 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -64,24 +64,15 @@ pub enum IsType {
6464
impl ObTypeLookup {
6565
fn new(py: Python) -> Self {
6666
// todo: delete before PR ready
67-
println!("[RUST] ObTypeLookup::new");
6867
Self {
6968
none: PyNone::type_object_raw(py) as usize,
7069
int: PyInt::type_object_raw(py) as usize,
7170
bool: PyBool::type_object_raw(py) as usize,
7271
float: PyFloat::type_object_raw(py) as usize,
7372
list: PyList::type_object_raw(py) as usize,
7473
dict: PyDict::type_object_raw(py) as usize,
75-
decimal_object: {
76-
// todo: delete before PR ready
77-
println!("[RUST] ObTypeLookup::new - loading decimal_object");
78-
py.import("decimal").unwrap().getattr("Decimal").unwrap().unbind()
79-
},
80-
fraction_object: {
81-
// todo: delete before PR ready
82-
println!("[RUST] ObTypeLookup::new - loading fraction_object");
83-
py.import("fractions").unwrap().getattr("Fraction").unwrap().unbind()
84-
},
74+
decimal_object: py.import("decimal").unwrap().getattr("Decimal").unwrap().unbind(),
75+
fraction_object: py.import("fractions").unwrap().getattr("Fraction").unwrap().unbind(),
8576
string: PyString::type_object_raw(py) as usize,
8677
bytes: PyBytes::type_object_raw(py) as usize,
8778
bytearray: PyByteArray::type_object_raw(py) as usize,
@@ -108,7 +99,6 @@ impl ObTypeLookup {
10899
}
109100

110101
pub fn is_type(&self, value: &Bound<'_, PyAny>, expected_ob_type: ObType) -> IsType {
111-
println!("[RUST] is_type - expected_ob_type: {expected_ob_type}");
112102
match self.ob_type_is_expected(Some(value), &value.get_type(), &expected_ob_type) {
113103
IsType::False => {
114104
if expected_ob_type == self.fallback_isinstance(value) {
@@ -129,7 +119,6 @@ impl ObTypeLookup {
129119
) -> IsType {
130120
let type_ptr = py_type.as_ptr();
131121
let ob_type = type_ptr as usize;
132-
println!("[RUST] ob_type_is_expected - ob_type: {ob_type}, expected_ob_type: {expected_ob_type}");
133122
let ans = match expected_ob_type {
134123
ObType::None => self.none == ob_type,
135124
ObType::Int => self.int == ob_type,
@@ -151,16 +140,8 @@ impl ObTypeLookup {
151140
ObType::Str => self.string == ob_type,
152141
ObType::List => self.list == ob_type,
153142
ObType::Dict => self.dict == ob_type,
154-
ObType::Decimal => {
155-
// todo: delete before PR ready
156-
println!("[RUST] ob_type_is_expected - checking ObType::Decimal");
157-
self.decimal_object.as_ptr() as usize == ob_type
158-
},
159-
ObType::Fraction => {
160-
// todo: delete before PR ready
161-
println!("[RUST] ob_type_is_expected - checking ObType::Fraction");
162-
self.fraction_object.as_ptr() as usize == ob_type
163-
},
143+
ObType::Decimal => self.decimal_object.as_ptr() as usize == ob_type,
144+
ObType::Fraction => self.fraction_object.as_ptr() as usize == ob_type,
164145
ObType::StrSubclass => self.string == ob_type && op_value.is_none(),
165146
ObType::Tuple => self.tuple == ob_type,
166147
ObType::Set => self.set == ob_type,
@@ -237,12 +218,8 @@ impl ObTypeLookup {
237218
} else if ob_type == self.dict {
238219
ObType::Dict
239220
} else if ob_type == self.decimal_object.as_ptr() as usize {
240-
// todo: delete before PR ready
241-
println!("[RUST] lookup_by_ob_type - found ObType::Decimal");
242221
ObType::Decimal
243222
} else if ob_type == self.fraction_object.as_ptr() as usize {
244-
// todo: delete before PR ready
245-
println!("[RUST] lookup_by_ob_type - found ObType::Fraction");
246223
ObType::Fraction
247224
} else if ob_type == self.bytes {
248225
ObType::Bytes
@@ -351,12 +328,8 @@ impl ObTypeLookup {
351328
} else if value.is_instance_of::<PyMultiHostUrl>() {
352329
ObType::MultiHostUrl
353330
} else if value.is_instance(self.decimal_object.bind(py)).unwrap_or(false) {
354-
// todo: delete before PR ready
355-
println!("[RUST] fallback_isinstance - found ObType::Decimal");
356331
ObType::Decimal
357332
} else if value.is_instance(self.fraction_object.bind(py)).unwrap_or(false) {
358-
// todo: delete before PR ready
359-
println!("[RUST] fallback_isinstance - found ObType::Fraction");
360333
ObType::Fraction
361334
} else if value.is_instance(self.uuid_object.bind(py)).unwrap_or(false) {
362335
ObType::Uuid

src/serializers/type_serializers/fraction.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,11 @@ use super::{
1616
#[derive(Debug)]
1717
pub struct FractionSerializer {}
1818

19-
static FRACTION_SERIALIZER: LazyLock<Arc<CombinedSerializer>> = LazyLock::new(|| Arc::new(FractionSerializer {}.into()));
19+
static FRACTION_SERIALIZER: LazyLock<Arc<CombinedSerializer>> =
20+
LazyLock::new(|| Arc::new(FractionSerializer {}.into()));
2021

2122
impl BuildSerializer for FractionSerializer {
22-
const EXPECTED_TYPE: &'static str = "decimal";
23+
const EXPECTED_TYPE: &'static str = "fraction";
2324

2425
fn build(
2526
_schema: &Bound<'_, PyDict>,
@@ -41,7 +42,6 @@ impl TypeSerializer for FractionSerializer {
4142
extra: &Extra,
4243
) -> PyResult<Py<PyAny>> {
4344
let _py = value.py();
44-
println!("[RUST] FractionSerializer to_python called");
4545
match extra.ob_type_lookup.is_type(value, ObType::Fraction) {
4646
IsType::Exact | IsType::Subclass => infer_to_python_known(ObType::Fraction, value, include, exclude, extra),
4747
IsType::False => {

src/serializers/type_serializers/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@ pub mod complex;
44
pub mod dataclass;
55
pub mod datetime_etc;
66
pub mod decimal;
7-
pub mod fraction;
87
pub mod definitions;
98
pub mod dict;
109
pub mod enum_;
1110
pub mod float;
1211
pub mod format;
12+
pub mod fraction;
1313
pub mod function;
1414
pub mod generator;
1515
pub mod json;

src/validators/fraction.rs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use std::sync::Arc;
33
use pyo3::exceptions::{PyTypeError, PyValueError};
44
use pyo3::intern;
55
use pyo3::sync::PyOnceLock;
6-
use pyo3::types::{IntoPyDict, PyDict, PyString, PyTuple, PyType};
6+
use pyo3::types::{PyDict, PyString, PyType};
77
use pyo3::{prelude::*, PyTypeInfo};
88

99
use crate::build_tools::{is_strict, schema_or_config_same};
@@ -77,12 +77,7 @@ impl BuildValidator for FractionValidator {
7777
}
7878
}
7979

80-
impl_py_gc_traverse!(FractionValidator {
81-
le,
82-
lt,
83-
ge,
84-
gt
85-
});
80+
impl_py_gc_traverse!(FractionValidator { le, lt, ge, gt });
8681

8782
fn extract_fraction_as_ints(fraction: &Bound<'_, PyAny>) -> ValResult<(i64, i64)> {
8883
let py = fraction.py();

0 commit comments

Comments
 (0)