summaryrefslogtreecommitdiffstats
path: root/Lib/re.py
Commit message (Collapse)AuthorAgeFilesLines
* bpo-47152: Convert the re module into a package (GH-32177)Serhiy Storchaka2022-04-021-364/+0
| | | The sre_* modules are now deprecated.
* bpo-31369: include ``RegexFlag`` in ``re.__all__`` (GH-30279)andrei kulakov2022-02-051-1/+2
| | | | | * added RegexFlag to re.__all__; added RegexFlag.NOFLAG Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
* bpo-40066: [Enum] skip failing doc test (GH-30637)Kumar Aditya2022-01-171-0/+2
|
* Revert "bpo-40066: [Enum] update str() and format() output (GH-30582)" ↵Victor Stinner2022-01-171-2/+0
| | | | | (GH-30632) This reverts commit acf7403f9baea3ae1119fc6b4a3298522188bf96.
* bpo-40066: [Enum] update str() and format() output (GH-30582)Ethan Furman2022-01-161-0/+2
| | | | | | | | | | | | | | | Undo rejected PEP-663 changes: - restore `repr()` to its 3.10 status - restore `str()` to its 3.10 status New changes: - `IntEnum` and `IntFlag` now leave `__str__` as the original `int.__str__` so that str() and format() return the same result - zero-valued flags without a name have a slightly changed repr(), e.g. `repr(Color(0)) == '<Color: 0>'` - update `dir()` for mixed-in types to return all the methods and attributes of the mixed-in type - added `_numeric_repr_` to `Flag` to control display of unnamed values - enums without doc strings have a more comprehensive doc string added - `ReprEnum` added -- inheriting from this makes it so only `__repr__` is replaced, not `__str__` nor `__format__`; `IntEnum`, `IntFlag`, and `StrEnum` all inherit from `ReprEnum`
* bpo-38659: [Enum] add _simple_enum decorator (GH-25497)Ethan Furman2021-04-211-1/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | add: * `_simple_enum` decorator to transform a normal class into an enum * `_test_simple_enum` function to compare * `_old_convert_` to enable checking `_convert_` generated enums `_simple_enum` takes a normal class and converts it into an enum: @simple_enum(Enum) class Color: RED = 1 GREEN = 2 BLUE = 3 `_old_convert_` works much like` _convert_` does, using the original logic: # in a test file import socket, enum CheckedAddressFamily = enum._old_convert_( enum.IntEnum, 'AddressFamily', 'socket', lambda C: C.isupper() and C.startswith('AF_'), source=_socket, ) `_test_simple_enum` takes a traditional enum and a simple enum and compares the two: # in the REPL or the same module as Color class CheckedColor(Enum): RED = 1 GREEN = 2 BLUE = 3 _test_simple_enum(CheckedColor, Color) _test_simple_enum(CheckedAddressFamily, socket.AddressFamily) Any important differences will raise a TypeError
* Revert "bpo-38659: [Enum] add _simple_enum decorator (GH-25285)" (GH-25476)Ethan Furman2021-04-201-2/+1
| | | This reverts commit dbac8f40e81eb0a29dc833e6409a1abf47467da6.
* bpo-38659: [Enum] add _simple_enum decorator (GH-25285)Ethan Furman2021-04-201-1/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | add: _simple_enum decorator to transform a normal class into an enum _test_simple_enum function to compare _old_convert_ to enable checking _convert_ generated enums _simple_enum takes a normal class and converts it into an enum: @simple_enum(Enum) class Color: RED = 1 GREEN = 2 BLUE = 3 _old_convert_ works much like _convert_ does, using the original logic: # in a test file import socket, enum CheckedAddressFamily = enum._old_convert_( enum.IntEnum, 'AddressFamily', 'socket', lambda C: C.isupper() and C.startswith('AF_'), source=_socket, ) test_simple_enum takes a traditional enum and a simple enum and compares the two: # in the REPL or the same module as Color class CheckedColor(Enum): RED = 1 GREEN = 2 BLUE = 3 _test_simple_enum(CheckedColor, Color) _test_simple_enum(CheckedAddressFamily, socket.AddressFamily) Any important differences will raise a TypeError
* bpo-40066: Enum: modify `repr()` and `str()` (GH-22392)Ethan Furman2021-03-311-16/+1
| | | | | | | | | * Enum: streamline repr() and str(); improve docs - repr() is now ``enum_class.member_name`` - stdlib global enums are ``module_name.member_name`` - str() is now ``member_name`` - add HOW-TO section for ``Enum`` - change main documentation to be an API reference
* bpo-38250: [Enum] single-bit flags are canonical (GH-24215)Ethan Furman2021-01-251-20/+11
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Flag members are now divided by one-bit verses multi-bit, with multi-bit being treated as aliases. Iterating over a flag only returns the contained single-bit flags. Iterating, repr(), and str() show members in definition order. When constructing combined-member flags, any extra integer values are either discarded (CONFORM), turned into ints (EJECT) or treated as errors (STRICT). Flag classes can specify which of those three behaviors is desired: >>> class Test(Flag, boundary=CONFORM): ... ONE = 1 ... TWO = 2 ... >>> Test(5) <Test.ONE: 1> Besides the three above behaviors, there is also KEEP, which should not be used unless necessary -- for example, _convert_ specifies KEEP as there are flag sets in the stdlib that are incomplete and/or inconsistent (e.g. ssl.Options). KEEP will, as the name suggests, keep all bits; however, iterating over a flag with extra bits will only return the canonical flags contained, not the extra bits. Iteration is now in member definition order. If member definition order matches increasing value order, then a more efficient method of flag decomposition is used; otherwise, sort() is called on the results of that method to get definition order. ``re`` module: repr() has been modified to support as closely as possible its previous output; the big difference is that inverted flags cannot be output as before because the inversion operation now always returns the comparable positive result; i.e. re.A|re.I|re.M|re.S is ~(re.L|re.U|re.S|re.T|re.DEBUG) in both of the above terms, the ``value`` is 282. re's tests have been updated to reflect the modifications to repr().
* bpo-40016: re docstring: Clarify relationship of inline and argument flags ↵Ram Rachum2020-03-251-2/+4
| | | | | | | (#19078) Co-authored-by: Terry Jan Reedy <tjreedy@udel.edu>
* bpo-36548: Improve the repr of re flags. (GH-12715)Serhiy Storchaka2019-05-311-16/+32
|
* bpo-34681: Rename class Pattern in sre_parse to State. (GH-9310)Serhiy Storchaka2018-09-181-1/+1
| | | Also rename corresponding attributes, parameters and variables.
* bpo-32338: OrderedDict import is no longer needed in re. (#4891)Serhiy Storchaka2018-03-111-9/+4
|
* bpo-30349: Raise FutureWarning for nested sets and set operations (#1553)Serhiy Storchaka2017-11-161-1/+2
| | | | in regular expressions.
* bpo-31671: re: Convert RegexFlag to int before compile (GH-3862)INADA Naoki2017-10-051-0/+4
| | | | | | sre_compile does bit test (e.g. `flags & SRE_FLAG_IGNORECASE`) in loop. `IntFlag.__and__` and `IntFlag.__new__` made it slower. So this commit convert it to normal int before passing flags to `sre_compile()`.
* bpo-30397: Add re.Pattern and re.Match. (#1646)Serhiy Storchaka2017-10-041-17/+18
|
* Trivial readability improvement (#3791)Barry Warsaw2017-09-271-1/+1
|
* bpo-28293: Don't completely dump the regex cache when full. (#3768)Serhiy Storchaka2017-09-261-2/+12
|
* bpo-30215: Make re.compile() locale agnostic. (#1361)Serhiy Storchaka2017-05-051-10/+2
| | | | | | Compiled regular expression objects with the re.LOCALE flag no longer depend on the locale at compile time. Only the locale at matching time affects the result of matching.
* bpo-29995: re.escape() now escapes only special characters. (#1007)Serhiy Storchaka2017-04-131-27/+9
|
* Issue #28637: Reapply changeset 223731925d06Victor Stinner2016-11-141-12/+21
| | | | | | | "issue28082: use IntFlag for re constants" by Ethan Furman. The re module is not more used in the site module and so adding "import enum" to re.py doesn't impact python_startup benchmark anymore.
* Issue #28637: Revert issue #28082, don't import enum in reVictor Stinner2016-11-071-21/+12
| | | | | | Importing the enum module in the re module slows down Python startup by 34% when Python is run from a virtual environment, or more generally when the re module is imported at startup but not the enum module.
* Issue #28193: Use lru_cache in the re module.Raymond Hettinger2016-09-191-11/+4
|
* issue28082: better name for FlagEthan Furman2016-09-111-2/+2
|
* issue28082: use IntFlag for re constantsEthan Furman2016-09-111-12/+21
|
* Issue #433028: Added support of modifier spans in regular expressions.Serhiy Storchaka2016-09-091-1/+1
|
* Removed unused imports.Serhiy Storchaka2016-04-241-1/+0
|
* Issue #22364: Improved some re error messages using regex for hints.Serhiy Storchaka2015-03-251-1/+1
|
* Issues #814253, #9179: Group references and conditional group references nowSerhiy Storchaka2015-02-211-2/+3
| | | | work in lookbehind assertions in regular expressions.
* merge 3.4 (#9179)Benjamin Peterson2014-11-301-3/+2
|\
| * backout 9fcf4008b626 (#9179) for further considerationBenjamin Peterson2014-11-301-3/+2
| |
* | Minor code clean up and improvements in the re module.Serhiy Storchaka2014-11-111-1/+1
| |
* | Issues #814253, #9179: Group references and conditional group references nowSerhiy Storchaka2014-11-071-2/+3
|\ \ | |/ | | | | work in lookbehind assertions in regular expressions.
| * Issues #814253, #9179: Group references and conditional group references nowSerhiy Storchaka2014-11-071-2/+3
| | | | | | | | work in lookbehind assertions in regular expressions.
* | Fixed compile error in issue #22410. The _locale module is optional.Serhiy Storchaka2014-10-301-1/+6
|\ \ | |/
| * Fixed compile error in issue #22410. The _locale module is optional.Serhiy Storchaka2014-10-301-1/+6
| |
* | Issue #22410: Module level functions in the re module now cache compiledSerhiy Storchaka2014-10-301-2/+9
|\ \ | |/ | | | | locale-dependent regular expressions taking into account the locale.
| * Issue #22410: Module level functions in the re module now cache compiledSerhiy Storchaka2014-10-301-2/+9
| | | | | | | | locale-dependent regular expressions taking into account the locale.
* | Issue #22510: Get rid of little overhead of testing re.DEBUG flag.Serhiy Storchaka2014-09-291-7/+5
| |
* | Removed a code for suport Python version <2.2.Serhiy Storchaka2014-09-281-11/+12
|/
* Issue #20426: When passing the re.DEBUG flag, re.compile() displays the ↵Antoine Pitrou2014-02-031-7/+10
|\ | | | | | | debug output every time it is called, regardless of the compilation cache.
| * Issue #20426: When passing the re.DEBUG flag, re.compile() displays the ↵Antoine Pitrou2014-02-031-7/+10
| | | | | | | | debug output every time it is called, regardless of the compilation cache.
* | Issue #16203: Add re.fullmatch() function and regex.fullmatch() method,Serhiy Storchaka2013-11-231-11/+17
| | | | | | | | | | | | which anchor the pattern at both ends of the string to match. Original patch by Matthew Barnett.
* | Back out accidentally pushed changeset b51218966201.Georg Brandl2013-10-131-17/+11
| |
* | Add re.fullmatch() function and regex.fullmatch() method, which anchor theGeorg Brandl2013-10-131-11/+17
| | | | | | | | | | | | | | pattern at both ends of the string to match. Patch by Matthew Barnett. Closes #16203.
* | Remove import functools from re module. The re module imports functools but ↵Christian Heimes2013-10-131-1/+0
|/ | | | never uses it.
* Issue #16564: Fixed a performance regression relative to Python 3.1 in theSerhiy Storchaka2013-03-161-6/+24
|\ | | | | | | caching of compiled regular expressions.
| * Issue #16564: Fixed a performance regression relative to Python 3.1 in theSerhiy Storchaka2013-03-161-9/+25
| | | | | | | | caching of compiled regular expressions.
* | Set cache sizes to a power-of-twoRaymond Hettinger2013-02-171-2/+2
| |