Skip to content

Commit dcafe86

Browse files
committed
Remove TypeInfo
1 parent bd04fcd commit dcafe86

File tree

15 files changed

+5
-856
lines changed

15 files changed

+5
-856
lines changed

newsfragments/5893.removed.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Remove the `TypeInfo` enum and the `FromPyObject::type_input` and `IntoPyObject::type_output` functions. They are replaced by the `PyStaticExpr` enum and the `FromPyObject::INPUT_TYPE` and the `IntoPyObject::OUTPUT_TYPE` associated constants.

src/conversion.rs

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
use crate::err::PyResult;
33
use crate::impl_::pyclass::ExtractPyClassWithClone;
44
#[cfg(feature = "experimental-inspect")]
5-
use crate::inspect::types::TypeInfo;
6-
#[cfg(feature = "experimental-inspect")]
75
use crate::inspect::{type_hint_identifier, type_hint_subscript, PyStaticExpr};
86
use crate::pyclass::boolean_struct::False;
97
use crate::pyclass::{PyClassGuardError, PyClassGuardMutError};
@@ -65,18 +63,6 @@ pub trait IntoPyObject<'py>: Sized {
6563
/// Performs the conversion.
6664
fn into_pyobject(self, py: Python<'py>) -> Result<Self::Output, Self::Error>;
6765

68-
/// Extracts the type hint information for this type when it appears as a return value.
69-
///
70-
/// For example, `Vec<u32>` would return `List[int]`.
71-
/// The default implementation returns `Any`, which is correct for any type.
72-
///
73-
/// For most types, the return value for this method will be identical to that of [`FromPyObject::type_input`].
74-
/// It may be different for some types, such as `Dict`, to allow duck-typing: functions return `Dict` but take `Mapping` as argument.
75-
#[cfg(feature = "experimental-inspect")]
76-
fn type_output() -> TypeInfo {
77-
TypeInfo::Any
78-
}
79-
8066
/// Converts sequence of Self into a Python object. Used to specialize `Vec<u8>`, `[u8; N]`
8167
/// and `SmallVec<[u8; N]>` as a sequence of bytes into a `bytes` object.
8268
#[doc(hidden)]
@@ -419,19 +405,6 @@ pub trait FromPyObject<'a, 'py>: Sized {
419405
/// [`Bound<'_, PyAny>::extract`](crate::types::any::PyAnyMethods::extract) or [`Py::extract`].
420406
fn extract(obj: Borrowed<'a, 'py, PyAny>) -> Result<Self, Self::Error>;
421407

422-
/// Extracts the type hint information for this type when it appears as an argument.
423-
///
424-
/// For example, `Vec<u32>` would return `Sequence[int]`.
425-
/// The default implementation returns `Any`, which is correct for any type.
426-
///
427-
/// For most types, the return value for this method will be identical to that of
428-
/// [`IntoPyObject::type_output`]. It may be different for some types, such as `Dict`,
429-
/// to allow duck-typing: functions return `Dict` but take `Mapping` as argument.
430-
#[cfg(feature = "experimental-inspect")]
431-
fn type_input() -> TypeInfo {
432-
TypeInfo::Any
433-
}
434-
435408
/// Specialization hook for extracting sequences for types like `Vec<u8>` and `[u8; N]`,
436409
/// where the bytes can be directly copied from some python objects without going through
437410
/// iteration.

src/conversions/either.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,6 @@
4444
//!
4545
//! [either](https://docs.rs/either/ "A library for easy idiomatic error handling and reporting in Rust applications")’s
4646
47-
#[cfg(feature = "experimental-inspect")]
48-
use crate::inspect::types::TypeInfo;
4947
#[cfg(feature = "experimental-inspect")]
5048
use crate::inspect::PyStaticExpr;
5149
#[cfg(feature = "experimental-inspect")]

src/conversions/smallvec.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@
1818
use crate::conversion::{FromPyObjectOwned, IntoPyObject};
1919
use crate::exceptions::PyTypeError;
2020
#[cfg(feature = "experimental-inspect")]
21-
use crate::inspect::types::TypeInfo;
22-
#[cfg(feature = "experimental-inspect")]
2321
use crate::inspect::PyStaticExpr;
2422
#[cfg(feature = "experimental-inspect")]
2523
use crate::type_hint_subscript;

src/conversions/std/map.rs

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
#[cfg(feature = "experimental-inspect")]
2-
use crate::inspect::types::TypeInfo;
3-
#[cfg(feature = "experimental-inspect")]
42
use crate::inspect::{type_hint_subscript, PyStaticExpr};
53
#[cfg(feature = "experimental-inspect")]
64
use crate::type_object::PyTypeInfo;
@@ -33,11 +31,6 @@ where
3331
}
3432
Ok(dict)
3533
}
36-
37-
#[cfg(feature = "experimental-inspect")]
38-
fn type_output() -> TypeInfo {
39-
TypeInfo::dict_of(K::type_output(), V::type_output())
40-
}
4134
}
4235

4336
impl<'a, 'py, K, V, H> IntoPyObject<'py> for &'a collections::HashMap<K, V, H>
@@ -61,11 +54,6 @@ where
6154
}
6255
Ok(dict)
6356
}
64-
65-
#[cfg(feature = "experimental-inspect")]
66-
fn type_output() -> TypeInfo {
67-
TypeInfo::dict_of(<&K>::type_output(), <&V>::type_output())
68-
}
6957
}
7058

7159
impl<'py, K, V> IntoPyObject<'py> for collections::BTreeMap<K, V>
@@ -88,11 +76,6 @@ where
8876
}
8977
Ok(dict)
9078
}
91-
92-
#[cfg(feature = "experimental-inspect")]
93-
fn type_output() -> TypeInfo {
94-
TypeInfo::dict_of(K::type_output(), V::type_output())
95-
}
9679
}
9780

9881
impl<'a, 'py, K, V> IntoPyObject<'py> for &'a collections::BTreeMap<K, V>
@@ -117,11 +100,6 @@ where
117100
}
118101
Ok(dict)
119102
}
120-
121-
#[cfg(feature = "experimental-inspect")]
122-
fn type_output() -> TypeInfo {
123-
TypeInfo::dict_of(<&K>::type_output(), <&V>::type_output())
124-
}
125103
}
126104

127105
impl<'py, K, V, S> FromPyObject<'_, 'py> for collections::HashMap<K, V, S>
@@ -147,11 +125,6 @@ where
147125
}
148126
Ok(ret)
149127
}
150-
151-
#[cfg(feature = "experimental-inspect")]
152-
fn type_input() -> TypeInfo {
153-
TypeInfo::mapping_of(K::type_input(), V::type_input())
154-
}
155128
}
156129

157130
impl<'py, K, V> FromPyObject<'_, 'py> for collections::BTreeMap<K, V>
@@ -176,11 +149,6 @@ where
176149
}
177150
Ok(ret)
178151
}
179-
180-
#[cfg(feature = "experimental-inspect")]
181-
fn type_input() -> TypeInfo {
182-
TypeInfo::mapping_of(K::type_input(), V::type_input())
183-
}
184152
}
185153

186154
#[cfg(test)]

src/conversions/std/num.rs

Lines changed: 0 additions & 102 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@ use crate::conversion::private::Reference;
22
use crate::conversion::{FromPyObjectSequence, IntoPyObject};
33
use crate::ffi_ptr_ext::FfiPtrExt;
44
#[cfg(feature = "experimental-inspect")]
5-
use crate::inspect::types::TypeInfo;
6-
#[cfg(feature = "experimental-inspect")]
75
use crate::inspect::PyStaticExpr;
86
use crate::py_result_ext::PyResultExt;
97
#[cfg(feature = "experimental-inspect")]
@@ -33,11 +31,6 @@ macro_rules! int_fits_larger_int {
3331
fn into_pyobject(self, py: Python<'py>) -> Result<Self::Output, Self::Error> {
3432
(self as $larger_type).into_pyobject(py)
3533
}
36-
37-
#[cfg(feature = "experimental-inspect")]
38-
fn type_output() -> TypeInfo {
39-
<$larger_type>::type_output()
40-
}
4134
}
4235

4336
impl<'py> IntoPyObject<'py> for &$rust_type {
@@ -51,11 +44,6 @@ macro_rules! int_fits_larger_int {
5144
fn into_pyobject(self, py: Python<'py>) -> Result<Self::Output, Self::Error> {
5245
(*self).into_pyobject(py)
5346
}
54-
55-
#[cfg(feature = "experimental-inspect")]
56-
fn type_output() -> TypeInfo {
57-
<$larger_type>::type_output()
58-
}
5947
}
6048

6149
impl FromPyObject<'_, '_> for $rust_type {
@@ -69,11 +57,6 @@ macro_rules! int_fits_larger_int {
6957
<$rust_type>::try_from(val)
7058
.map_err(|e| exceptions::PyOverflowError::new_err(e.to_string()))
7159
}
72-
73-
#[cfg(feature = "experimental-inspect")]
74-
fn type_input() -> TypeInfo {
75-
<$larger_type>::type_input()
76-
}
7760
}
7861
};
7962
}
@@ -120,11 +103,6 @@ macro_rules! int_convert_u64_or_i64 {
120103
.cast_into_unchecked())
121104
}
122105
}
123-
124-
#[cfg(feature = "experimental-inspect")]
125-
fn type_output() -> TypeInfo {
126-
TypeInfo::builtin("int")
127-
}
128106
}
129107
impl<'py> IntoPyObject<'py> for &$rust_type {
130108
type Target = PyInt;
@@ -148,11 +126,6 @@ macro_rules! int_convert_u64_or_i64 {
148126
fn extract(obj: Borrowed<'_, '_, PyAny>) -> Result<$rust_type, Self::Error> {
149127
extract_int!(obj, !0, $pylong_as_ll_or_ull, $force_index_call)
150128
}
151-
152-
#[cfg(feature = "experimental-inspect")]
153-
fn type_input() -> TypeInfo {
154-
Self::type_output()
155-
}
156129
}
157130
};
158131
}
@@ -174,11 +147,6 @@ macro_rules! int_fits_c_long {
174147
.cast_into_unchecked())
175148
}
176149
}
177-
178-
#[cfg(feature = "experimental-inspect")]
179-
fn type_output() -> TypeInfo {
180-
TypeInfo::builtin("int")
181-
}
182150
}
183151

184152
impl<'py> IntoPyObject<'py> for &$rust_type {
@@ -193,11 +161,6 @@ macro_rules! int_fits_c_long {
193161
fn into_pyobject(self, py: Python<'py>) -> Result<Self::Output, Self::Error> {
194162
(*self).into_pyobject(py)
195163
}
196-
197-
#[cfg(feature = "experimental-inspect")]
198-
fn type_output() -> TypeInfo {
199-
TypeInfo::builtin("int")
200-
}
201164
}
202165

203166
impl<'py> FromPyObject<'_, 'py> for $rust_type {
@@ -211,11 +174,6 @@ macro_rules! int_fits_c_long {
211174
<$rust_type>::try_from(val)
212175
.map_err(|e| exceptions::PyOverflowError::new_err(e.to_string()))
213176
}
214-
215-
#[cfg(feature = "experimental-inspect")]
216-
fn type_input() -> TypeInfo {
217-
Self::type_output()
218-
}
219177
}
220178
};
221179
}
@@ -236,11 +194,6 @@ impl<'py> IntoPyObject<'py> for u8 {
236194
}
237195
}
238196

239-
#[cfg(feature = "experimental-inspect")]
240-
fn type_output() -> TypeInfo {
241-
TypeInfo::builtin("int")
242-
}
243-
244197
#[inline]
245198
fn owned_sequence_into_pyobject<I>(
246199
iter: I,
@@ -269,11 +222,6 @@ impl<'py> IntoPyObject<'py> for &'_ u8 {
269222
u8::into_pyobject(*self, py)
270223
}
271224

272-
#[cfg(feature = "experimental-inspect")]
273-
fn type_output() -> TypeInfo {
274-
TypeInfo::builtin("int")
275-
}
276-
277225
#[inline]
278226
fn borrowed_sequence_into_pyobject<I>(
279227
iter: I,
@@ -302,11 +250,6 @@ impl<'py> FromPyObject<'_, 'py> for u8 {
302250
u8::try_from(val).map_err(|e| exceptions::PyOverflowError::new_err(e.to_string()))
303251
}
304252

305-
#[cfg(feature = "experimental-inspect")]
306-
fn type_input() -> TypeInfo {
307-
Self::type_output()
308-
}
309-
310253
#[inline]
311254
fn sequence_extractor(
312255
obj: Borrowed<'_, 'py, PyAny>,
@@ -437,11 +380,6 @@ mod fast_128bit_int_conversion {
437380
Ok(int_from_le_bytes::<{ $is_signed }>(py, &bytes))
438381
}
439382
}
440-
441-
#[cfg(feature = "experimental-inspect")]
442-
fn type_output() -> TypeInfo {
443-
TypeInfo::builtin("int")
444-
}
445383
}
446384

447385
impl<'py> IntoPyObject<'py> for &$rust_type {
@@ -456,11 +394,6 @@ mod fast_128bit_int_conversion {
456394
fn into_pyobject(self, py: Python<'py>) -> Result<Self::Output, Self::Error> {
457395
(*self).into_pyobject(py)
458396
}
459-
460-
#[cfg(feature = "experimental-inspect")]
461-
fn type_output() -> TypeInfo {
462-
TypeInfo::builtin("int")
463-
}
464397
}
465398

466399
impl FromPyObject<'_, '_> for $rust_type {
@@ -513,11 +446,6 @@ mod fast_128bit_int_conversion {
513446
Ok(<$rust_type>::from_ne_bytes(buffer))
514447
}
515448
}
516-
517-
#[cfg(feature = "experimental-inspect")]
518-
fn type_input() -> TypeInfo {
519-
Self::type_output()
520-
}
521449
}
522450
};
523451
}
@@ -591,11 +519,6 @@ mod slow_128bit_int_conversion {
591519
.cast_into_unchecked())
592520
}
593521
}
594-
595-
#[cfg(feature = "experimental-inspect")]
596-
fn type_output() -> TypeInfo {
597-
TypeInfo::builtin("int")
598-
}
599522
}
600523

601524
impl<'py> IntoPyObject<'py> for &$rust_type {
@@ -610,11 +533,6 @@ mod slow_128bit_int_conversion {
610533
fn into_pyobject(self, py: Python<'py>) -> Result<Self::Output, Self::Error> {
611534
(*self).into_pyobject(py)
612535
}
613-
614-
#[cfg(feature = "experimental-inspect")]
615-
fn type_output() -> TypeInfo {
616-
TypeInfo::builtin("int")
617-
}
618536
}
619537

620538
impl FromPyObject<'_, '_> for $rust_type {
@@ -640,11 +558,6 @@ mod slow_128bit_int_conversion {
640558
Ok((<$rust_type>::from(upper) << SHIFT) | lower)
641559
}
642560
}
643-
644-
#[cfg(feature = "experimental-inspect")]
645-
fn type_input() -> TypeInfo {
646-
Self::type_output()
647-
}
648561
}
649562
};
650563
}
@@ -681,11 +594,6 @@ macro_rules! nonzero_int_impl {
681594
fn into_pyobject(self, py: Python<'py>) -> Result<Self::Output, Self::Error> {
682595
self.get().into_pyobject(py)
683596
}
684-
685-
#[cfg(feature = "experimental-inspect")]
686-
fn type_output() -> TypeInfo {
687-
TypeInfo::builtin("int")
688-
}
689597
}
690598

691599
impl<'py> IntoPyObject<'py> for &$nonzero_type {
@@ -700,11 +608,6 @@ macro_rules! nonzero_int_impl {
700608
fn into_pyobject(self, py: Python<'py>) -> Result<Self::Output, Self::Error> {
701609
(*self).into_pyobject(py)
702610
}
703-
704-
#[cfg(feature = "experimental-inspect")]
705-
fn type_output() -> TypeInfo {
706-
TypeInfo::builtin("int")
707-
}
708611
}
709612

710613
impl FromPyObject<'_, '_> for $nonzero_type {
@@ -718,11 +621,6 @@ macro_rules! nonzero_int_impl {
718621
<$nonzero_type>::try_from(val)
719622
.map_err(|_| exceptions::PyValueError::new_err("invalid zero value"))
720623
}
721-
722-
#[cfg(feature = "experimental-inspect")]
723-
fn type_input() -> TypeInfo {
724-
<$primitive_type>::type_input()
725-
}
726624
}
727625
};
728626
}

0 commit comments

Comments
 (0)