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

make GILOnceCell::get_or_try_init_type_ref public #4542

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

glevco
Copy link

@glevco glevco commented Sep 10, 2024

Resolves #4516.

  • Change GILOnceCell::get_or_try_init_type_ref to GILOnceCell::import and make it public API, adding an example for it.
  • Update "Executing existing Python code" section of the guide:
    • Add mention to GILOnceCell::import.
    • Change Python::eval_bound (which is deprecated) to Python::eval.
    • Change Python::run_bound (which is deprecated) to Python::run, also adding missing link.

Copy link
Member

@mejrs mejrs left a comment

Choose a reason for hiding this comment

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

Change PyModule::import suggestion to Python::import instead

Why? I don't have a strong opinion either way, but slightly prefer PyModule::import.

src/sync.rs Outdated
/// # });
/// ```
///
pub fn get_or_try_init_type_ref<'py>(
Copy link
Member

Choose a reason for hiding this comment

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

This can use a better name. Maybe just "import"? 🤔

Copy link
Author

Choose a reason for hiding this comment

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

I agree, but then maybe it should be implemented for GILOnceCell<Py<T>> where T: PyTypeInfo instead of GILOnceCell<Py<PyType>>? Otherwise, I would call it import_type.

Copy link
Member

Choose a reason for hiding this comment

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

I'd be fine with that. I think you want T: PyTypeCheck rather than T: PyTypeInfo, though.

Copy link
Author

Choose a reason for hiding this comment

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

Right, done in 79568f6!

@glevco
Copy link
Author

glevco commented Sep 11, 2024

@mejrs

Why? I don't have a strong opinion either way, but slightly prefer PyModule::import.

Since Python::import was used in the implementation of get_or_try_init_type_ref, I assumed it was preferable. Also, it pairs nicely with the other entries in this section of the guide, as they recommend other "global" functions such as Python::eval and Python::run. What do you think?

@davidhewitt
Copy link
Member

I prefer PyModule::import too, I think it's nicer to think of that as a "constructor" for the PyModule type.

@mejrs
Copy link
Member

mejrs commented Sep 14, 2024

What do you think?

From a documentation perspective I would prefer that people visit PyModule::import over Python::import. Python has a lot of not module related api, and its page is a lot bigger.

Also, using "constructor" syntax also makes it clear that when they use it, they're getting a module (rather than something arbitrary like from foo import bar might do).

@glevco
Copy link
Author

glevco commented Sep 14, 2024

@davidhewitt @mejrs Fair enough, I reverted the guide back to PyModule::import in 79568f6. I also changed the method name to GILOnceCell::import and made its impl generic for PyTypeCheck, as discussed above. I updated the PR description accordingly.

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.

Make GILOnceCell<Py<PyType>>'s get_or_try_init_type_ref public
3 participants