Skip to content

bpo-30398: Add a docstring for re.error.#1647

Merged
serhiy-storchaka merged 2 commits intopython:masterfrom
serhiy-storchaka:re-error-docstring
May 27, 2017
Merged

bpo-30398: Add a docstring for re.error.#1647
serhiy-storchaka merged 2 commits intopython:masterfrom
serhiy-storchaka:re-error-docstring

Conversation

@serhiy-storchaka
Copy link
Copy Markdown
Member

No description provided.

@serhiy-storchaka serhiy-storchaka added type-bug An unexpected behavior, bug, or error needs backport to 3.5 labels May 18, 2017
@mention-bot
Copy link
Copy Markdown

@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.

Copy link
Copy Markdown
Member

@terryjreedy terryjreedy left a comment

Choose a reason for hiding this comment

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

It is nice to have this documented. Main question is when it can be raised.

# should this really be here?

class error(Exception):
'''Exception raised for invalid regular expressions.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

If this is only raised during compilation, then
"Exception raised while compiling invalid regular expressions.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

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.


msg: The unformatted error message
pattern: The regular expression pattern
pos: The index of pattern where compilation failed
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

'in' instead of 'of' sounds better to me.
If this is also raised during matching, what would this be?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

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.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

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.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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.

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
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

'source line' and 'source column'?

@serhiy-storchaka serhiy-storchaka merged commit 12d6b5d into python:master May 27, 2017
@serhiy-storchaka serhiy-storchaka deleted the re-error-docstring branch May 27, 2017 13:12
serhiy-storchaka added a commit to serhiy-storchaka/cpython that referenced this pull request May 27, 2017
Also document that some attributes may be None.
(cherry picked from commit 12d6b5d)
serhiy-storchaka added a commit to serhiy-storchaka/cpython that referenced this pull request May 27, 2017
Also document that some attributes may be None.
(cherry picked from commit 12d6b5d)
serhiy-storchaka added a commit that referenced this pull request May 27, 2017
Also document that some attributes may be None.
(cherry picked from commit 12d6b5d)
serhiy-storchaka added a commit that referenced this pull request May 27, 2017
Also document that some attributes may be None.
(cherry picked from commit 12d6b5d)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

type-bug An unexpected behavior, bug, or error

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants