pyo3 icon indicating copy to clipboard operation
pyo3 copied to clipboard

Add '__pyo3_version__` to native modules compiled with PyO3

Open davidhewitt opened this issue 2 years ago • 2 comments

From https://github.com/sphinx-doc/sphinx/issues/11662#issuecomment-1702462095

To be cheeky, could I ask if there is there a 'blessed' way to introspect if a module is PyO3 generated? It seems the variables mod.build_profile and mod.build_info might be heuristics, but a PYO3 = True flag or similar (a la 'pypy' in sys.modules) might be useful for future cases?

I can't think of one which exists right now, it seems like a practical improvement to have __pyo3_version__ as a standard attribute in compiled PyO3 modules?

davidhewitt avatar Sep 01 '23 09:09 davidhewitt

In my experience, if a name is addressing two concerns (i.e. PyO3 and version), it's often wise to actually model those concerns separately, similar to how __spec__ models details about a modules spec. Please consider adding the detail as __pyo3__.version or similar.

jaraco avatar Sep 03 '23 14:09 jaraco

Removing Good First Issue as this probably requires integration with the pyo3-runtime Python module to be completed.

davidhewitt avatar Sep 16 '23 11:09 davidhewitt