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

Removed -[OC_PythonObject pyObject] #460

Open
schriftgestalt opened this issue Mar 25, 2022 · 3 comments
Open

Removed -[OC_PythonObject pyObject] #460

schriftgestalt opened this issue Mar 25, 2022 · 3 comments

Comments

@schriftgestalt
Copy link

schriftgestalt commented Mar 25, 2022

I do use this method in my code like this to extract the text of the traceback:

- (BOOL)reportPythonException:(NSException *)exception {
	NSDictionary *userInfo = [exception userInfo];
	PyObject *traceback = [userInfo[@"__pyobjc_exc_traceback__"] pyObject];
	if (traceback) {
		PyGILState_STATE gilState = PyGILState_Ensure();
		PyObject *type = [userInfo[@"__pyobjc_exc_type__"] pyObject];
		PyObject *value = [userInfo[@"__pyobjc_exc_value__"] pyObject];
		PyObject *mod = PyImport_ImportModule("traceback");
		if (!mod) {
			return NO;
		}
		PyObject *list = PyObject_CallMethod(mod, "format_exception", "OOO", type, value, traceback);
		…

Is there a better way to do this?

(I mean the changes in #393)

@ronaldoussoren
Copy link
Owner

That's an interesting use case.

The alternative is to call [value __pyobjc_PythonObject__], which will return a new reference (that is, you'll have to call Py_DECREF on the result). This will also work in older versions.

I'll have to think about a cleaner solution for this, my alternative is still an implementation detail and will break if I ever add support for CPython sub interpreters to PyObjC. That won't be anytime soon though, there are several blockers on the CPython side.

@schriftgestalt
Copy link
Author

The alternative is to call [value pyobjc_PythonObject]

That works. Thanks.

@ronaldoussoren
Copy link
Owner

I'm leaving this issue open with an updated title, there should be a documented and tested way to do this.

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

No branches or pull requests

2 participants