| 1 | use crate::stub_type::*; |
| 2 | use ::pyo3::{ |
| 3 | basic::CompareOp, |
| 4 | pybacked::{PyBackedBytes, PyBackedStr}, |
| 5 | pyclass::boolean_struct::False, |
| 6 | types::*, |
| 7 | Bound, Py, PyClass, PyRef, PyRefMut, |
| 8 | }; |
| 9 | use maplit::hashset; |
| 10 | |
| 11 | impl PyStubType for PyAny { |
| 12 | fn type_output() -> TypeInfo { |
| 13 | TypeInfo { |
| 14 | name: "typing.Any" .to_string(), |
| 15 | import: hashset! { "typing" .into() }, |
| 16 | } |
| 17 | } |
| 18 | } |
| 19 | |
| 20 | impl<T: PyStubType> PyStubType for Py<T> { |
| 21 | fn type_input() -> TypeInfo { |
| 22 | T::type_input() |
| 23 | } |
| 24 | fn type_output() -> TypeInfo { |
| 25 | T::type_output() |
| 26 | } |
| 27 | } |
| 28 | |
| 29 | impl<T: PyStubType + PyClass> PyStubType for PyRef<'_, T> { |
| 30 | fn type_input() -> TypeInfo { |
| 31 | T::type_input() |
| 32 | } |
| 33 | fn type_output() -> TypeInfo { |
| 34 | T::type_output() |
| 35 | } |
| 36 | } |
| 37 | |
| 38 | impl<T: PyStubType + PyClass<Frozen = False>> PyStubType for PyRefMut<'_, T> { |
| 39 | fn type_input() -> TypeInfo { |
| 40 | T::type_input() |
| 41 | } |
| 42 | fn type_output() -> TypeInfo { |
| 43 | T::type_output() |
| 44 | } |
| 45 | } |
| 46 | |
| 47 | impl<T: PyStubType> PyStubType for Bound<'_, T> { |
| 48 | fn type_input() -> TypeInfo { |
| 49 | T::type_input() |
| 50 | } |
| 51 | fn type_output() -> TypeInfo { |
| 52 | T::type_output() |
| 53 | } |
| 54 | } |
| 55 | |
| 56 | macro_rules! impl_builtin { |
| 57 | ($ty:ty, $pytype:expr) => { |
| 58 | impl PyStubType for $ty { |
| 59 | fn type_output() -> TypeInfo { |
| 60 | TypeInfo { |
| 61 | name: $pytype.to_string(), |
| 62 | import: HashSet::new(), |
| 63 | } |
| 64 | } |
| 65 | } |
| 66 | }; |
| 67 | } |
| 68 | |
| 69 | impl_builtin!(PyInt, "int" ); |
| 70 | impl_builtin!(PyFloat, "float" ); |
| 71 | impl_builtin!(PyList, "list" ); |
| 72 | impl_builtin!(PyTuple, "tuple" ); |
| 73 | impl_builtin!(PySlice, "slice" ); |
| 74 | impl_builtin!(PyDict, "dict" ); |
| 75 | impl_builtin!(PySet, "set" ); |
| 76 | impl_builtin!(PyString, "str" ); |
| 77 | impl_builtin!(PyBackedStr, "str" ); |
| 78 | impl_builtin!(PyByteArray, "bytearray" ); |
| 79 | impl_builtin!(PyBytes, "bytes" ); |
| 80 | impl_builtin!(PyBackedBytes, "bytes" ); |
| 81 | impl_builtin!(PyType, "type" ); |
| 82 | impl_builtin!(CompareOp, "int" ); |
| 83 | |