Skip to content

Commit 3bf516e

Browse files
committed
Add back original module
1 parent ee8cdef commit 3bf516e

File tree

6 files changed

+45
-44
lines changed

6 files changed

+45
-44
lines changed

src/exceptions.rs

Lines changed: 11 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -72,10 +72,7 @@ macro_rules! import_exception {
7272
///
7373
/// [`pyo3::import_exception!`]: https://docs.rs/pyo3/latest/pyo3/macro.import_exception.html "import_exception in pyo3"
7474
#[repr(transparent)]
75-
#[allow(
76-
non_camel_case_types,
77-
reason = "matches imported exception name, e.g. `socket.herror`"
78-
)]
75+
#[allow(non_camel_case_types, reason = "matches imported exception name, e.g. `socket.herror`")]
7976
pub struct $name($crate::PyAny);
8077

8178
$crate::impl_exception_boilerplate!($name);
@@ -84,17 +81,15 @@ macro_rules! import_exception {
8481
$name,
8582
$name::type_object_raw,
8683
stringify!($name),
87-
stringify!($module)
84+
stringify!($module),
85+
#module=::std::option::Option::Some(stringify!($module))
8886
);
8987

9088
impl $name {
9189
fn type_object_raw(py: $crate::Python<'_>) -> *mut $crate::ffi::PyTypeObject {
9290
use $crate::types::PyTypeMethods;
9391
static TYPE_OBJECT: $crate::impl_::exceptions::ImportedExceptionTypeObject =
94-
$crate::impl_::exceptions::ImportedExceptionTypeObject::new(
95-
stringify!($module),
96-
stringify!($name),
97-
);
92+
$crate::impl_::exceptions::ImportedExceptionTypeObject::new(stringify!($module), stringify!($name));
9893
TYPE_OBJECT.get(py).as_type_ptr()
9994
}
10095
}
@@ -206,19 +201,15 @@ macro_rules! create_exception_type_object {
206201
$crate::create_exception_type_object!($module, $name, $base, ::std::option::Option::None);
207202
};
208203
($module: expr, $name: ident, $base: ty, Some($doc: expr)) => {
209-
$crate::create_exception_type_object!(
210-
$module,
211-
$name,
212-
$base,
213-
::std::option::Option::Some($crate::ffi::c_str!($doc))
214-
);
204+
$crate::create_exception_type_object!($module, $name, $base, ::std::option::Option::Some($crate::ffi::c_str!($doc)));
215205
};
216206
($module: expr, $name: ident, $base: ty, $doc: expr) => {
217207
$crate::pyobject_native_type_core!(
218208
$name,
219209
$name::type_object_raw,
220210
stringify!($name),
221-
stringify!($module)
211+
stringify!($module),
212+
#module=::std::option::Option::Some(stringify!($module))
222213
);
223214

224215
impl $name {
@@ -228,21 +219,15 @@ macro_rules! create_exception_type_object {
228219
PyOnceLock::new();
229220

230221
TYPE_OBJECT
231-
.get_or_init(py, || {
222+
.get_or_init(py, ||
232223
$crate::PyErr::new_type(
233224
py,
234-
$crate::ffi::c_str!(concat!(
235-
stringify!($module),
236-
".",
237-
stringify!($name)
238-
)),
225+
$crate::ffi::c_str!(concat!(stringify!($module), ".", stringify!($name))),
239226
$doc,
240227
::std::option::Option::Some(&py.get_type::<$base>()),
241228
::std::option::Option::None,
242-
)
243-
.expect("Failed to initialize new exception type.")
244-
})
245-
.as_ptr() as *mut $crate::ffi::PyTypeObject
229+
).expect("Failed to initialize new exception type.")
230+
).as_ptr() as *mut $crate::ffi::PyTypeObject
246231
}
247232
}
248233
};

src/types/any.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ pyobject_native_type_info!(
4646
pyobject_native_static_type_object!(ffi::PyBaseObject_Type),
4747
"builtins",
4848
"object",
49+
Some("builtins"),
4950
#checkfunction=PyObject_Check
5051
);
5152

src/types/datetime.rs

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,7 @@ pyobject_native_type!(
203203
|py| expect_datetime_api(py).DateType,
204204
"datetime",
205205
"date",
206+
#module=Some("datetime"),
206207
#checkfunction=PyDate_Check
207208
);
208209
#[cfg(not(Py_LIMITED_API))]
@@ -216,7 +217,8 @@ pyobject_native_type_core!(
216217
TYPE.import(py, "datetime", "date").unwrap().as_type_ptr()
217218
},
218219
"datetime",
219-
"date"
220+
"date",
221+
#module=Some("datetime")
220222
);
221223

222224
impl PyDate {
@@ -291,6 +293,7 @@ pyobject_native_type!(
291293
|py| expect_datetime_api(py).DateTimeType,
292294
"datetime",
293295
"datetime",
296+
#module=Some("datetime"),
294297
#checkfunction=PyDateTime_Check
295298
);
296299
#[cfg(not(Py_LIMITED_API))]
@@ -306,7 +309,8 @@ pyobject_native_type_core!(
306309
.as_type_ptr()
307310
},
308311
"datetime",
309-
"datetime"
312+
"datetime",
313+
#module=Some("datetime")
310314
);
311315

312316
impl PyDateTime {
@@ -527,6 +531,7 @@ pyobject_native_type!(
527531
|py| expect_datetime_api(py).TimeType,
528532
"datetime",
529533
"time",
534+
#module=Some("datetime"),
530535
#checkfunction=PyTime_Check
531536
);
532537
#[cfg(not(Py_LIMITED_API))]
@@ -540,7 +545,8 @@ pyobject_native_type_core!(
540545
TYPE.import(py, "datetime", "time").unwrap().as_type_ptr()
541546
},
542547
"datetime",
543-
"time"
548+
"time",
549+
#module=Some("datetime")
544550
);
545551

546552
impl PyTime {
@@ -697,7 +703,9 @@ pyobject_native_type!(
697703
PyTzInfo,
698704
crate::ffi::PyObject,
699705
|py| expect_datetime_api(py).TZInfoType,
700-
"datetime", "tzinfo",
706+
"datetime",
707+
"tzinfo",
708+
#module=Some("datetime"),
701709
#checkfunction=PyTZInfo_Check
702710
);
703711
#[cfg(not(Py_LIMITED_API))]
@@ -711,7 +719,8 @@ pyobject_native_type_core!(
711719
TYPE.import(py, "datetime", "tzinfo").unwrap().as_type_ptr()
712720
},
713721
"datetime",
714-
"tzinfo"
722+
"tzinfo",
723+
#module=Some("datetime")
715724
);
716725

717726
impl PyTzInfo {
@@ -807,7 +816,9 @@ pyobject_native_type!(
807816
PyDelta,
808817
crate::ffi::PyDateTime_Delta,
809818
|py| expect_datetime_api(py).DeltaType,
810-
"datetime", "timedelta",
819+
"datetime",
820+
"timedelta",
821+
#module=Some("datetime"),
811822
#checkfunction=PyDelta_Check
812823
);
813824
#[cfg(not(Py_LIMITED_API))]
@@ -823,7 +834,8 @@ pyobject_native_type_core!(
823834
.as_type_ptr()
824835
},
825836
"datetime",
826-
"timedelta"
837+
"timedelta",
838+
#module=Some("datetime")
827839
);
828840

829841
impl PyDelta {

src/types/iterator.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ pyobject_native_type_core!(
4242
},
4343
"collections.abc",
4444
"Iterator",
45+
#module=Some("collections.abc"),
4546
#checkfunction=ffi::PyIter_Check
4647
);
4748

src/types/mod.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -151,11 +151,11 @@ macro_rules! pyobject_native_static_type_object(
151151
#[doc(hidden)]
152152
#[macro_export]
153153
macro_rules! pyobject_native_type_info(
154-
($name:ty, $typeobject:expr, $module:expr, $python_name:expr $(, #checkfunction=$checkfunction:path)? $(;$generics:ident)*) => {
154+
($name:ty, $typeobject:expr, $type_hint_module:expr, $type_hint_name:expr, $module:expr $(, #checkfunction=$checkfunction:path)? $(;$generics:ident)*) => {
155155
// SAFETY: macro caller has upheld the safety contracts
156156
unsafe impl<$($generics,)*> $crate::type_object::PyTypeInfo for $name {
157157
const NAME: &'static str = stringify!($name);
158-
const MODULE: ::std::option::Option<&'static str> = ::std::option::Option::Some($module);
158+
const MODULE: ::std::option::Option<&'static str> = $module;
159159

160160
#[inline]
161161
#[allow(clippy::redundant_closure_call)]
@@ -188,12 +188,12 @@ macro_rules! pyobject_native_type_info(
188188
#[doc(hidden)]
189189
#[macro_export]
190190
macro_rules! pyobject_native_type_info(
191-
($name:ty, $typeobject:expr, $module:expr, $python_name:expr $(, #checkfunction=$checkfunction:path)? $(;$generics:ident)*) => {
191+
($name:ty, $typeobject:expr, $type_hint_module:expr, $type_hint_name:expr, $module:expr $(, #checkfunction=$checkfunction:path)? $(;$generics:ident)*) => {
192192
// SAFETY: macro caller has upheld the safety contracts
193193
unsafe impl<$($generics,)*> $crate::type_object::PyTypeInfo for $name {
194194
const NAME: &'static str = stringify!($name);
195-
const MODULE: ::std::option::Option<&'static str> = ::std::option::Option::Some($module);
196-
const TYPE_HINT: $crate::inspect::TypeHint = $crate::inspect::TypeHint::module_attr($module, $python_name);
195+
const MODULE: ::std::option::Option<&'static str> = $module;
196+
const TYPE_HINT: $crate::inspect::TypeHint = $crate::inspect::TypeHint::module_attr($type_hint_module, $type_hint_name);
197197

198198
#[inline]
199199
#[allow(clippy::redundant_closure_call)]
@@ -226,12 +226,12 @@ macro_rules! pyobject_native_type_info(
226226
#[doc(hidden)]
227227
#[macro_export]
228228
macro_rules! pyobject_native_type_core {
229-
($name:ty, $typeobject:expr, $module:expr, $python_name:expr $(, #checkfunction=$checkfunction:path)? $(;$generics:ident)*) => {
229+
($name:ty, $typeobject:expr, $type_hint_module:expr, $type_hint_name:expr, #module=$module:expr $(, #checkfunction=$checkfunction:path)? $(;$generics:ident)*) => {
230230
$crate::pyobject_native_type_named!($name $(;$generics)*);
231-
$crate::pyobject_native_type_info!($name, $typeobject, $module, $python_name $(, #checkfunction=$checkfunction)? $(;$generics)*);
231+
$crate::pyobject_native_type_info!($name, $typeobject, $type_hint_module, $type_hint_name, $module $(, #checkfunction=$checkfunction)? $(;$generics)*);
232232
};
233-
($name:ty, $typeobject:expr, $python_name:expr $(, #checkfunction=$checkfunction:path)? $(;$generics:ident)*) => {
234-
$crate::pyobject_native_type_core!($name, $typeobject, "builtins", $python_name $(, #checkfunction=$checkfunction)? $(;$generics)*);
233+
($name:ty, $typeobject:expr, $type_hint_module:expr, $type_hint_name:expr $(, #checkfunction=$checkfunction:path)? $(;$generics:ident)*) => {
234+
$crate::pyobject_native_type_core!($name, $typeobject, $type_hint_module, $type_hint_name, #module=::std::option::Option::Some("builtins") $(, #checkfunction=$checkfunction)? $(;$generics)*);
235235
};
236236
}
237237

@@ -263,8 +263,8 @@ macro_rules! pyobject_native_type_sized {
263263
#[doc(hidden)]
264264
#[macro_export]
265265
macro_rules! pyobject_native_type {
266-
($name:ty, $layout:path, $typeobject:expr, $module:expr, $python_name:expr $(, #checkfunction=$checkfunction:path)? $(;$generics:ident)*) => {
267-
$crate::pyobject_native_type_core!($name, $typeobject, $module, $python_name $(, #checkfunction=$checkfunction)? $(;$generics)*);
266+
($name:ty, $layout:path, $typeobject:expr, $type_hint_module:expr, $type_hint_name:expr $(, #module=$module:expr)? $(, #checkfunction=$checkfunction:path)? $(;$generics:ident)*) => {
267+
$crate::pyobject_native_type_core!($name, $typeobject, $type_hint_module, $type_hint_name $(, #module=$module)? $(, #checkfunction=$checkfunction)? $(;$generics)*);
268268
// To prevent inheriting native types with ABI3
269269
#[cfg(not(Py_LIMITED_API))]
270270
$crate::pyobject_native_type_sized!($name, $layout $(;$generics)*);

src/types/weakref/reference.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ pyobject_native_type!(
3131
pyobject_native_static_type_object!(ffi::_PyWeakref_RefType),
3232
"weakref",
3333
"ReferenceType",
34+
#module=Some("weakref"),
3435
#checkfunction=ffi::PyWeakref_CheckRefExact
3536
);
3637

@@ -46,6 +47,7 @@ pyobject_native_type_core!(
4647
},
4748
"weakref",
4849
"ReferenceType",
50+
#module=Some("weakref"),
4951
#checkfunction=ffi::PyWeakref_CheckRef
5052
);
5153

0 commit comments

Comments
 (0)