From: Serhiy Storchaka Date: Sat, 27 May 2017 13:12:48 +0000 (+0300) Subject: bpo-30398: Add a docstring for re.error. (#1647) X-Git-Tag: v3.7.0a1~731 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=12d6b5d156377c0877931a03ef2439dccb2f3711;p=python bpo-30398: Add a docstring for re.error. (#1647) Also document that some attributes may be None. --- diff --git a/Doc/library/re.rst b/Doc/library/re.rst index 96338dc27b..0b9d9755f3 100644 --- a/Doc/library/re.rst +++ b/Doc/library/re.rst @@ -839,15 +839,15 @@ form. .. attribute:: pos - The index of *pattern* where compilation failed. + The index in *pattern* where compilation failed (may be ``None``). .. attribute:: lineno - The line corresponding to *pos*. + The line corresponding to *pos* (may be ``None``). .. attribute:: colno - The column corresponding to *pos*. + The column corresponding to *pos* (may be ``None``). .. versionchanged:: 3.5 Added additional attributes. diff --git a/Lib/sre_constants.py b/Lib/sre_constants.py index b0164312d0..0261e9e956 100644 --- a/Lib/sre_constants.py +++ b/Lib/sre_constants.py @@ -21,6 +21,17 @@ from _sre import MAXREPEAT, MAXGROUPS # should this really be here? class error(Exception): + """Exception raised for invalid regular expressions. + + Attributes: + + msg: The unformatted error message + pattern: The regular expression pattern + pos: The index in the pattern where compilation failed (may be None) + lineno: The line corresponding to pos (may be None) + colno: The column corresponding to pos (may be None) + """ + def __init__(self, msg, pattern=None, pos=None): self.msg = msg self.pattern = pattern