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

Better names for PyErr::ptype, PyErr::pvalue and PyErr::ptraceback #1987

Closed
davidhewitt opened this issue Nov 12, 2021 · 10 comments · Fixed by #2026
Closed

Better names for PyErr::ptype, PyErr::pvalue and PyErr::ptraceback #1987

davidhewitt opened this issue Nov 12, 2021 · 10 comments · Fixed by #2026

Comments

@davidhewitt
Copy link
Member

I keep thinking I'd like to give nicer names for PyErr::ptype, PyErr::pvalue, and PyErr::ptraceback.

As far as I'm aware the "p" prefix is a hangover from C hungarian notation; it feels very out of place here as we're not even returning raw pointers from these methods.

I would love to have just .type, .value and .traceback but type is a reserved keyword.

Could potentially be .get_type, .value, and .traceback (inspired by PyAny::get_type which is presumably trying to solve the same problem). Or get_ prefix for all three, but that feels slightly more verbose than it needs to be.

Any ideas welcome.

@birkenfeld
Copy link
Member

err.r#type() 😄

@davidhewitt
Copy link
Member Author

I mean while technically possible, I don't think I want that 😅

@Eric-Arellano
Copy link
Contributor

Eric-Arellano commented Nov 13, 2021

Maybe .err_type? I like .get_type() otherwise

@mejrs
Copy link
Member

mejrs commented Nov 13, 2021

Some people resort to kind because of this.

@davidhewitt
Copy link
Member Author

Yes, I used kind in a recent piece of pyo3-macros-backend code. However, I think that given Python calls this thing the "exception type", I'm unconvinced kind works here...

@birkenfeld
Copy link
Member

kind is also quite unfamiliar to Python programmers. get_type() is clear and nicer than type_() which would be the other convention to avoid clashes.

@davidhewitt
Copy link
Member Author

davidhewitt commented Nov 14, 2021

Yes I think I'm quite happy with get_type too. I just can't decide whether the other methods should be get_value/value and get_traceback/traceback.

Maybe get_value & get_traceback for consistency? get_ isn't that long a prefix and these methods aren't used that frequently...

@Eric-Arellano
Copy link
Contributor

Eric-Arellano commented Nov 14, 2021

I personally like traceback(py) and value(py) more than using get_. I think having to pass Python as an arg already makes clear it's a getter and that it's more than just reading from a struct.

While the inconsistency is a little weird, I don't think it's the end of the world. And not every call site will use all 3 (I think pants only needed traceback)

@mejrs
Copy link
Member

mejrs commented Nov 14, 2021

err.r#type() 😄

If we're going for familiarity to Python programmers, this is (I think) the only thing that emits a helpful compiler error when .type() is tried. So perhaps we should not be so quick to dismiss it.

@davidhewitt
Copy link
Member Author

True, but we already have PyAny::get_type, which I'm not aware of having been confusing to any users.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants