Skip to content

bpo-38530: Offer suggestions on AttributeError #16856

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

Merged
merged 7 commits into from
Apr 14, 2021

Conversation

pablogsal
Copy link
Member

@pablogsal pablogsal commented Oct 19, 2019

@pablogsal
Copy link
Member Author

@serhiy-storchaka Would you like to take a look at this PR when you have some time? :)

Add News entry

Make 'name' and 'obj' public attributes of AttributeError

Fix various issues with the implementation

Add more tests

Simplify implementation and rename public function

More cosmetic changes

Add more tests

Add more tests
Copy link
Member

@vstinner vstinner left a comment

Choose a reason for hiding this comment

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

First review. I like the overall approach (I expect a low overhead when raising AttributeError).

PyException_HEAD
PyObject *obj;
PyObject *name;
} PyAttributeErrorObject;
Copy link
Member

Choose a reason for hiding this comment

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

https://www.python.org/dev/peps/pep-0473/ was rejected because it was too broad, but this PR adds a single exception, which sounds ok according to the resolution: https://mail.python.org/pipermail/python-dev/2019-March/156692.html

My main worry is the risk of creating "more" and "worse" exception cycles, but Pablo says that it sounds unlikely: https://bugs.python.org/issue38530#msg354975

return_val = -1;
goto exit;
}
exc->args = new_args;
Copy link
Member

Choose a reason for hiding this comment

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

Why not storing suggestions in a new Exception field, rather than replacing existing args? I may break some applications.

Copy link
Member Author

Choose a reason for hiding this comment

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

Because I don't want to touch the reporting facility to inspect said field or allowing users to inspect it manually

Copy link
Member Author

@pablogsal pablogsal Apr 10, 2021

Choose a reason for hiding this comment

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

Also, this substitution only happens before printing the value because it has been not caught. Nobody should be able to inspect this exception later, no? Notice this only happens in the default exception display, so if someone has a custom handler, they will not see this AFAIK.

Copy link
Member

Choose a reason for hiding this comment

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

Code level comment:
I don't understand why exc->args = new_args; Isn't it set by Py_SETREF?

Higher level comment:
Why do you replace exc->args instead of just printing suggestion after _PyErr_Display() or in _PyErr_Display()?

Copy link
Member Author

Choose a reason for hiding this comment

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

I don't understand why exc->args = new_args; Isn't it set by Py_SETREF?

I forgot to remove that after updated the code after @vstinner suggestions.

Why do you replace exc->args instead of just printing suggestion after _PyErr_Display() or in _PyErr_Display()?

Actually, this is a very good point, this can make the code cleaner. I will implement this

@pablogsal pablogsal force-pushed the suggestions2 branch 4 times, most recently from d9b74da to 97bf9e4 Compare April 14, 2021 00:54
@pablogsal pablogsal merged commit 37494b4 into python:master Apr 14, 2021
@pablogsal pablogsal deleted the suggestions2 branch April 14, 2021 01:36
@python python deleted a comment from bedevere-bot Apr 14, 2021
Snowapril added a commit to Snowapril/RustPython that referenced this pull request Oct 10, 2021
`suggestions.rs` is almost porting of implementation of
[this](python/cpython#16856) and
[this](python/cpython#25397).

Signed-off-by: snowapril <[email protected]>
Snowapril added a commit to Snowapril/RustPython that referenced this pull request Oct 11, 2021
`suggestions.rs` is almost porting of implementation of
[this](python/cpython#16856) and
[this](python/cpython#25397).

Signed-off-by: snowapril <[email protected]>
Snowapril added a commit to Snowapril/RustPython that referenced this pull request Oct 11, 2021
`suggestions.rs` is almost porting of implementation of
[this](python/cpython#16856) and
[this](python/cpython#25397).

Signed-off-by: snowapril <[email protected]>
Snowapril added a commit to Snowapril/RustPython that referenced this pull request Oct 11, 2021
`suggestions.rs` is almost porting of implementation of
[this](python/cpython#16856) and
[this](python/cpython#25397).

Signed-off-by: snowapril <[email protected]>
Snowapril added a commit to Snowapril/RustPython that referenced this pull request Oct 11, 2021
`suggestions.rs` is almost porting of implementation of
[this](python/cpython#16856) and
[this](python/cpython#25397).

Signed-off-by: snowapril <[email protected]>
Snowapril added a commit to Snowapril/RustPython that referenced this pull request Oct 13, 2021
`suggestions.rs` is almost porting of implementation of
[this](python/cpython#16856) and
[this](python/cpython#25397).

Signed-off-by: snowapril <[email protected]>
Snowapril added a commit to Snowapril/RustPython that referenced this pull request Oct 13, 2021
`suggestions.rs` is almost porting of implementation of
[this](python/cpython#16856) and
[this](python/cpython#25397).

Signed-off-by: snowapril <[email protected]>
Snowapril added a commit to Snowapril/RustPython that referenced this pull request Oct 13, 2021
`suggestions.rs` is almost porting of implementation of
[this](python/cpython#16856) and
[this](python/cpython#25397).

Signed-off-by: snowapril <[email protected]>
Snowapril added a commit to Snowapril/RustPython that referenced this pull request Oct 13, 2021
`suggestions.rs` is almost porting of implementation of
[this](python/cpython#16856) and
[this](python/cpython#25397).

Signed-off-by: snowapril <[email protected]>
Snowapril added a commit to Snowapril/RustPython that referenced this pull request Oct 14, 2021
`suggestions.rs` is almost porting of implementation of
[this](python/cpython#16856) and
[this](python/cpython#25397).

Signed-off-by: snowapril <[email protected]>
Snowapril added a commit to Snowapril/RustPython that referenced this pull request Oct 14, 2021
`suggestions.rs` is almost porting of implementation of
[this](python/cpython#16856) and
[this](python/cpython#25397).

Signed-off-by: snowapril <[email protected]>
Snowapril added a commit to Snowapril/RustPython that referenced this pull request Oct 14, 2021
`suggestions.rs` is almost porting of implementation of
[this](python/cpython#16856) and
[this](python/cpython#25397).

Signed-off-by: snowapril <[email protected]>
Snowapril added a commit to Snowapril/RustPython that referenced this pull request Oct 15, 2021
`suggestions.rs` is almost porting of implementation of
[this](python/cpython#16856) and
[this](python/cpython#25397).

Signed-off-by: snowapril <[email protected]>
Snowapril added a commit to Snowapril/RustPython that referenced this pull request Oct 16, 2021
`suggestions.rs` is almost porting of implementation of
[this](python/cpython#16856) and
[this](python/cpython#25397).

Signed-off-by: snowapril <[email protected]>
Snowapril added a commit to Snowapril/RustPython that referenced this pull request Oct 18, 2021
`suggestions.rs` is almost porting of implementation of
[this](python/cpython#16856) and
[this](python/cpython#25397).

Signed-off-by: snowapril <[email protected]>
Snowapril added a commit to Snowapril/RustPython that referenced this pull request Oct 18, 2021
`suggestions.rs` is almost porting of implementation of
[this](python/cpython#16856) and
[this](python/cpython#25397).

Signed-off-by: snowapril <[email protected]>
Snowapril added a commit to Snowapril/RustPython that referenced this pull request Oct 20, 2021
`suggestions.rs` is almost porting of implementation of
[this](python/cpython#16856) and
[this](python/cpython#25397).

Signed-off-by: snowapril <[email protected]>
Snowapril added a commit to Snowapril/RustPython that referenced this pull request Oct 20, 2021
`suggestions.rs` is almost porting of implementation of
[this](python/cpython#16856) and
[this](python/cpython#25397).

Signed-off-by: snowapril <[email protected]>
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.

5 participants