bpo-30398: Add a docstring for re.error.#1647
bpo-30398: Add a docstring for re.error.#1647serhiy-storchaka merged 2 commits intopython:masterfrom
Conversation
|
@serhiy-storchaka, thanks for your PR! By analyzing the history of the files in this pull request, we identified @freddrake to be a potential reviewer. |
terryjreedy
left a comment
There was a problem hiding this comment.
It is nice to have this documented. Main question is when it can be raised.
Lib/sre_constants.py
Outdated
| # should this really be here? | ||
|
|
||
| class error(Exception): | ||
| '''Exception raised for invalid regular expressions. |
There was a problem hiding this comment.
If this is only raised during compilation, then
"Exception raised while compiling invalid regular expressions.
There was a problem hiding this comment.
It is also raised by Pattern.sub() and Match.expand() when the replacement string contains invalid group reference. E.g. re.compile(r'\w').sub(r'\1', 'a'), re.match(r'\w', 'a').expand(r'\1'). Technically it is raised not during compilation, but immediately after it from user's point of view.
Lib/sre_constants.py
Outdated
|
|
||
| msg: The unformatted error message | ||
| pattern: The regular expression pattern | ||
| pos: The index of pattern where compilation failed |
There was a problem hiding this comment.
'in' instead of 'of' sounds better to me.
If this is also raised during matching, what would this be?
There was a problem hiding this comment.
The wording is copied from the module documentation (see bpo-22578). Should it be updated too?
Attributes pattern, pos, lineno and colno can be None if it is hard to determine the point of failure.
There was a problem hiding this comment.
The re module documentation is copied from the json module documentation, which was copied from the simplejson documentation. If change the wording it makes sense to change it consistently in all these places.
There was a problem hiding this comment.
Leave 'of' alone then. My comment on 'of' to 'in' was about a 60% change - 40% leave alone judgment. But your previous comment reveals that failure can occur during matching (which is the re equivalent of execution). Source lineno and colno are only relevant when failure is during matching.
Lib/sre_constants.py
Outdated
| pattern: The regular expression pattern | ||
| pos: The index of pattern where compilation failed | ||
| lineno: The line corresponding to pos | ||
| colno: The column corresponding to pos |
There was a problem hiding this comment.
'source line' and 'source column'?
31f5f03 to
7531128
Compare
Also document that some attributes may be None. (cherry picked from commit 12d6b5d)
Also document that some attributes may be None. (cherry picked from commit 12d6b5d)
No description provided.