pyo3 icon indicating copy to clipboard operation
pyo3 copied to clipboard

[RFC] split PyErr::new() into multiple methods

Open birkenfeld opened this issue 1 year ago • 3 comments

Intended to start a discussion, about APIs, but also names :)

Similar to call(), introduces new0(), new1() and new_args(), and the same on Exception types as new_err0(), new_err1() and new_err_args().

After the deprecation cycle, new1() could be renamed back to new(), since it is the one used in the vast majority of cases.

I kept PyErrArguments, but it's now only implemented for tuples, not for all Python-convertible types.

birkenfeld avatar Aug 02 '24 09:08 birkenfeld

Related: I have been wondering for a while about a new call syntax and you have prompted me to actually write that up: #4414

Maybe we could have py_call!{ PyValueError(a, b, c) } ? 🤔

I think new1 here as suggested is "call this with one positional argument"? We should be careful as our .call1 for object calls is "call this object with a tuple of arguments".

davidhewitt avatar Aug 02 '24 09:08 davidhewitt

Good point... I'm not fond of the names anyway, especially the new1 would probably be new in a green field, and could be after the deprecation cycle.

Could new0 be empty? IMO doesn't work too well for exceptions...

birkenfeld avatar Aug 02 '24 10:08 birkenfeld

Changed the names to new_empty, new_arg, and new_args, with the expectation to rename new_arg back to new after two versions.

new_empty could also be done away with completely, since it's seldom used, and replaced by new_args(()).

birkenfeld avatar Aug 24 '24 14:08 birkenfeld