Skip to content

Commit 12d6b5d

Browse files
bpo-30398: Add a docstring for re.error. (#1647)
Also document that some attributes may be None.
1 parent 5becf38 commit 12d6b5d

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
@@ -839,15 +839,15 @@ form.
839839

840840
.. attribute:: pos
841841

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

844844
.. attribute:: lineno
845845

846-
The line corresponding to *pos*.
846+
The line corresponding to *pos* (may be ``None``).
847847

848848
.. attribute:: colno
849849

850-
The column corresponding to *pos*.
850+
The column corresponding to *pos* (may be ``None``).
851851

852852
.. versionchanged:: 3.5
853853
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)