From: Serhiy Storchaka Date: Sat, 27 May 2017 13:37:40 +0000 (+0300) Subject: [3.6] bpo-30398: Add a docstring for re.error. (GH-1647) (#1830) X-Git-Tag: v3.6.2rc1~121 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b52c68a5a3f546cbbe1589f8bb3e51bfd55a6c15;p=thirdparty%2FPython%2Fcpython.git [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) --- diff --git a/Doc/library/re.rst b/Doc/library/re.rst index 944c6fb10d6c..5ae304d25e13 100644 --- a/Doc/library/re.rst +++ b/Doc/library/re.rst @@ -828,15 +828,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 fc684ae96fd3..a6e8a1f08d68 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