diff --git a/newsfragments/5387.added.md b/newsfragments/5387.added.md new file mode 100644 index 00000000000..9b96ac46353 --- /dev/null +++ b/newsfragments/5387.added.md @@ -0,0 +1 @@ +Add `PyTypeCheck::classinfo_object` that returns an object that can be used as parameter in `isinstance` or `issubclass` \ No newline at end of file diff --git a/newsfragments/5387.changed.md b/newsfragments/5387.changed.md new file mode 100644 index 00000000000..8c737793ef0 --- /dev/null +++ b/newsfragments/5387.changed.md @@ -0,0 +1,2 @@ +- Fetch type name dynamically on cast errors instead of using `PyTypeCheck::NAME` +- Deprecate `PyTypeCheck::NAME`, please `TypeTypeCheck::classinfo_object` to get the expected type and format it at runtime. \ No newline at end of file diff --git a/src/conversions/chrono.rs b/src/conversions/chrono.rs index d250cfc03d5..0a2a56c3530 100644 --- a/src/conversions/chrono.rs +++ b/src/conversions/chrono.rs @@ -692,11 +692,11 @@ mod tests { let none = py.None().into_bound(py); assert_eq!( none.extract::().unwrap_err().to_string(), - "TypeError: 'NoneType' object cannot be converted to 'PyDelta'" + "TypeError: 'NoneType' object cannot be converted to 'timedelta'" ); assert_eq!( none.extract::().unwrap_err().to_string(), - "TypeError: 'NoneType' object cannot be converted to 'PyTzInfo'" + "TypeError: 'NoneType' object cannot be converted to 'tzinfo'" ); assert_eq!( none.extract::().unwrap_err().to_string(), @@ -704,25 +704,25 @@ mod tests { ); assert_eq!( none.extract::().unwrap_err().to_string(), - "TypeError: 'NoneType' object cannot be converted to 'PyTime'" + "TypeError: 'NoneType' object cannot be converted to 'time'" ); assert_eq!( none.extract::().unwrap_err().to_string(), - "TypeError: 'NoneType' object cannot be converted to 'PyDate'" + "TypeError: 'NoneType' object cannot be converted to 'date'" ); assert_eq!( none.extract::().unwrap_err().to_string(), - "TypeError: 'NoneType' object cannot be converted to 'PyDateTime'" + "TypeError: 'NoneType' object cannot be converted to 'datetime'" ); assert_eq!( none.extract::>().unwrap_err().to_string(), - "TypeError: 'NoneType' object cannot be converted to 'PyDateTime'" + "TypeError: 'NoneType' object cannot be converted to 'datetime'" ); assert_eq!( none.extract::>() .unwrap_err() .to_string(), - "TypeError: 'NoneType' object cannot be converted to 'PyDateTime'" + "TypeError: 'NoneType' object cannot be converted to 'datetime'" ); }); } diff --git a/src/conversions/jiff.rs b/src/conversions/jiff.rs index 7ad84516f47..42d31527841 100644 --- a/src/conversions/jiff.rs +++ b/src/conversions/jiff.rs @@ -553,31 +553,31 @@ mod tests { let none = py.None().into_bound(py); assert_eq!( none.extract::().unwrap_err().to_string(), - "TypeError: 'NoneType' object cannot be converted to 'PyDelta'" + "TypeError: 'NoneType' object cannot be converted to 'timedelta'" ); assert_eq!( none.extract::().unwrap_err().to_string(), - "TypeError: 'NoneType' object cannot be converted to 'PyTzInfo'" + "TypeError: 'NoneType' object cannot be converted to 'tzinfo'" ); assert_eq!( none.extract::().unwrap_err().to_string(), - "TypeError: 'NoneType' object cannot be converted to 'PyTzInfo'" + "TypeError: 'NoneType' object cannot be converted to 'tzinfo'" ); assert_eq!( none.extract::