Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cleanup: deprecate PyTypeObject trait #2287

Merged
merged 1 commit into from
Apr 23, 2022

Conversation

davidhewitt
Copy link
Member

The PyTypeObject trait has become a bit meaningless over time. The PyTypeInfo trait essentially covers the same role with additional functionality; there is even a blanket implementation of PyTypeObject for T: PyTypeInfo which is the only implementation I'm aware of.

To make things simpler, I suggest we fold the trait into PyTypeInfo.

#[cfg(test)]
mod tests {
#[test]
#[allow(deprecated)]
Copy link
Member Author

@davidhewitt davidhewitt Apr 9, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this line is commented out and <PyList as crate::PyTypeInfo> replaced with just PyList, this is the compiler output:

warning: use of deprecated trait `type_object::PyTypeObject`: PyTypeObject::type_object was moved to PyTypeInfo::type_object
   --> src/type_object.rs:240:20
    |
240 |         use super::PyTypeObject;
    |                    ^^^^^^^^^^^^
    |
    = note: `#[warn(deprecated)]` on by default

warning: use of deprecated trait `type_object::PyTypeObject`: PyTypeObject::type_object was moved to PyTypeInfo::type_object
   --> src/type_object.rs:243:31
    |
243 |         fn get_type_object<T: PyTypeObject>(py: Python<'_>) -> &PyType {
    |                               ^^^^^^^^^^^^

error[E0599]: no function or associated item named `type_object` found for struct `PyList` in the current scope
   --> src/type_object.rs:249:58
    |
249 |                 get_type_object::<PyList>(py).is(PyList::type_object(py)))
    |                                                          ^^^^^^^^^^^ function or associated item not found in `PyList`
    |
   ::: src/types/list.rs:18:1
    |
18  | pub struct PyList(PyAny);
    | ------------------------- function or associated item `type_object` not found for this
    |
    = help: items from traits can only be used if the trait is in scope
help: the following trait is implemented but not in scope; perhaps add a `use` for it:
    |
237 |     use crate::type_object::PyTypeInfo;
    |

... hopefully this is enough for users to figure out how to upgrade.

@davidhewitt
Copy link
Member Author

Will wait for merging this until 0.16.4 is done.

@davidhewitt davidhewitt merged commit 8ef9e54 into PyO3:main Apr 23, 2022
@davidhewitt davidhewitt deleted the kill-type-object branch April 23, 2022 14:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants