Skip to content

Commit b52c68a

Browse files
[3.6] bpo-30398: Add a docstring for re.error. (GH-1647) (#1830)
Also document that some attributes may be None. (cherry picked from commit 12d6b5d)
1 parent 584ef2a commit b52c68a

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

Doc/library/re.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -828,15 +828,15 @@ form.
828828

829829
.. attribute:: pos
830830

831-
The index of *pattern* where compilation failed.
831+
The index in *pattern* where compilation failed (may be ``None``).
832832

833833
.. attribute:: lineno
834834

835-
The line corresponding to *pos*.
835+
The line corresponding to *pos* (may be ``None``).
836836

837837
.. attribute:: colno
838838

839-
The column corresponding to *pos*.
839+
The column corresponding to *pos* (may be ``None``).
840840

841841
.. versionchanged:: 3.5
842842
Added additional attributes.

Lib/sre_constants.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,17 @@
2121
# should this really be here?
2222

2323
class error(Exception):
24+
"""Exception raised for invalid regular expressions.
25+
26+
Attributes:
27+
28+
msg: The unformatted error message
29+
pattern: The regular expression pattern
30+
pos: The index in the pattern where compilation failed (may be None)
31+
lineno: The line corresponding to pos (may be None)
32+
colno: The column corresponding to pos (may be None)
33+
"""
34+
2435
def __init__(self, msg, pattern=None, pos=None):
2536
self.msg = msg
2637
self.pattern = pattern

0 commit comments

Comments
 (0)