constants.py 1.3 KB

12345678910111213141516171819202122232425262728293031
  1. # Licensed under the GPL: https://www.gnu.org/licenses/old-licenses/gpl-2.0.html
  2. # For details: https://github.com/pylint-dev/pylint/blob/main/LICENSE
  3. # Copyright (c) https://github.com/pylint-dev/pylint/blob/main/CONTRIBUTORS.txt
  4. import operator
  5. import re
  6. import sys
  7. from pathlib import Path
  8. # This is faster/terser without f-strings:
  9. # '"%d%d%d" % sys.version_info[:3]': (best of 5: 214 nanoseconds per loop)
  10. # '"".join(str(x) for x in sys.version_info[:3])'`: best of 5: 546 nanoseconds per loop
  11. # pylint: disable-next=consider-using-f-string
  12. SYS_VERS_STR = "%d%d%d" % sys.version_info[:3] # noqa: UP031
  13. TITLE_UNDERLINES = ["", "=", "-", "."]
  14. UPDATE_OPTION = "--update-functional-output"
  15. UPDATE_FILE = Path("pylint-functional-test-update")
  16. # Common sub-expressions.
  17. _MESSAGE = {"msg": r"[a-z][a-z\-]+"}
  18. # Matches a #,
  19. # - followed by a comparison operator and a Python version (optional),
  20. # - followed by a line number with a +/- (optional),
  21. # - followed by a list of bracketed message symbols.
  22. # Used to extract expected messages from testdata files.
  23. _EXPECTED_RE = re.compile(
  24. r"\s*#\s*(?:(?P<line>[+-]?[0-9]+):)?" # pylint: disable=consider-using-f-string
  25. r"(?:(?P<op>[><=]+) *(?P<version>[0-9.]+):)?"
  26. r"\s*\[(?P<msgs>{msg}(?:,\s*{msg})*)]".format(**_MESSAGE)
  27. )
  28. _OPERATORS = {">": operator.gt, "<": operator.lt, ">=": operator.ge, "<=": operator.le}