Skip to content

Commit c4c5b1e

Browse files
authored
Stubs: use _typeshed.Incomplete in traits default values (#5744)
Alias of typing.Any that highlight that the value should be replaced by a better annotation (in the implementation of the traits...). Makes clearer what is a trait implemented without annotation set and what is PyAny.
1 parent 76a090b commit c4c5b1e

File tree

3 files changed

+4
-3
lines changed

3 files changed

+4
-3
lines changed

newsfragments/5744.changed.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Stubs: use `_typeshed.Incomplete` instead of `typing.Any` as default value in traits. Allows to distinguish between `PyAny` and not implementations when annotations are not overridden.

src/conversion.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ pub trait IntoPyObject<'py>: Sized {
6161
/// For most types, the return value for this method will be identical to that of [`FromPyObject::INPUT_TYPE`].
6262
/// It may be different for some types, such as `Dict`, to allow duck-typing: functions return `Dict` but take `Mapping` as argument.
6363
#[cfg(feature = "experimental-inspect")]
64-
const OUTPUT_TYPE: PyStaticExpr = type_hint_identifier!("typing", "Any");
64+
const OUTPUT_TYPE: PyStaticExpr = type_hint_identifier!("_typeshed", "Incomplete");
6565

6666
/// Performs the conversion.
6767
fn into_pyobject(self, py: Python<'py>) -> Result<Self::Output, Self::Error>;
@@ -416,7 +416,7 @@ pub trait FromPyObject<'a, 'py>: Sized {
416416
/// For example, `Vec<u32>` would be `collections.abc.Sequence[int]`.
417417
/// The default value is `typing.Any`, which is correct for any type.
418418
#[cfg(feature = "experimental-inspect")]
419-
const INPUT_TYPE: PyStaticExpr = type_hint_identifier!("typing", "Any");
419+
const INPUT_TYPE: PyStaticExpr = type_hint_identifier!("_typeshed", "Incomplete");
420420

421421
/// Extracts `Self` from the bound smart pointer `obj`.
422422
///

src/type_object.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ pub unsafe trait PyTypeInfo: Sized {
5858

5959
/// Provides the full python type as a type hint.
6060
#[cfg(feature = "experimental-inspect")]
61-
const TYPE_HINT: PyStaticExpr = type_hint_identifier!("typing", "Any");
61+
const TYPE_HINT: PyStaticExpr = type_hint_identifier!("_typeshed", "Incomplete");
6262

6363
/// Returns the PyTypeObject instance for this type.
6464
fn type_object_raw(py: Python<'_>) -> *mut ffi::PyTypeObject;

0 commit comments

Comments
 (0)