Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

coverage run fails with a re.error with Python 3.9a6+ #988

Closed
pquentin opened this issue May 11, 2020 · 4 comments
Closed

coverage run fails with a re.error with Python 3.9a6+ #988

pquentin opened this issue May 11, 2020 · 4 comments
Labels
bug Something isn't working not our bug The problem was elsewhere

Comments

@pquentin
Copy link

coverage run fails with a re.error in Python nightly

To Reproduce

  1. Python version: 3.9.0a6+ (heads/master:85bdec1, May 10 2020, 05:50:51)
  2. coverage 5.1
  3. This failed in the CI build of urllib3 (https://github.com/urllib3/urllib3/blob/master/.travis.yml) which runs nox -s test-3.9
  4. coverage run --parallel-mode -m pytest -r a --tb=native --no-success-flaky-report test/

Sorry, I did not try this outside of a failing CI job: https://travis-ci.org/github/urllib3/urllib3/jobs/685596004

By comparing the last known good build, I can tell that the problem has been introduced in one of those commits: python/cpython@f01d1be...85bdec1

Expected behavior

I would expect the tests to run.

Additional context

Instead, I get the following traceback:

Traceback (most recent call last):
  File "/home/travis/build/urllib3/urllib3/.nox/test-3-9/bin/coverage", line 8, in <module>
    sys.exit(main())
  File "/home/travis/build/urllib3/urllib3/.nox/test-3-9/lib/python3.9/site-packages/coverage/cmdline.py", line 827, in main
    status = CoverageScript().command_line(argv)
  File "/home/travis/build/urllib3/urllib3/.nox/test-3-9/lib/python3.9/site-packages/coverage/cmdline.py", line 555, in command_line
    return self.do_run(options, args)
  File "/home/travis/build/urllib3/urllib3/.nox/test-3-9/lib/python3.9/site-packages/coverage/cmdline.py", line 700, in do_run
    self.coverage.start()
  File "/home/travis/build/urllib3/urllib3/.nox/test-3-9/lib/python3.9/site-packages/coverage/control.py", line 525, in start
    self._init_for_start()
  File "/home/travis/build/urllib3/urllib3/.nox/test-3-9/lib/python3.9/site-packages/coverage/control.py", line 487, in _init_for_start
    self._inorout.configure(self.config)
  File "/home/travis/build/urllib3/urllib3/.nox/test-3-9/lib/python3.9/site-packages/coverage/inorout.py", line 192, in configure
    self.omit_match = FnmatchMatcher(self.omit)
  File "/home/travis/build/urllib3/urllib3/.nox/test-3-9/lib/python3.9/site-packages/coverage/files.py", line 273, in __init__
    self.re = fnmatches_to_regex(self.pats, case_insensitive=env.WINDOWS)
  File "/home/travis/build/urllib3/urllib3/.nox/test-3-9/li/python3.9/site-packages/coverage/files.py", line 325, in fnmatches_to_regex
    compiled = re.compile(join_regex(regexes), flags=flags)
  File "/opt/python/3.9-dev/lib/python3.9/re.py", line 252, in compile
    return _compile(pattern, flags)
  File "/opt/python/3.9-dev/lib/python3.9/re.py", line 304, in _compile
    p = sre_compile.compile(pattern, flags)
  File "/opt/python/3.9-dev/lib/python3.9/sre_compile.py", line 764, in compile
    p = sre_parse.parse(p, flags)
  File "/opt/python/3.9-dev/lib/python3.9/sre_parse.py", line 948, in parse
    p = _parse_sub(source, state, flags & SRE_FLAG_VERBOSE, 0)
  File "/opt/python/3.9-dev/lib/python3.9/sre_parse.py", line 443, in _parse_sub
    itemsappend(_parse(source, state, verbose, nested + 1,
  File "/opt/python/3.9-dev/lib/python3.9/sre_parse.py", line 834, in _parse
    p = _parse_sub(source, state, sub_verbose, nested + 1)
  File "/opt/python/3.9-dev/lib/python3.9/sre_parse.py", line 443, in _parse_sub
    itemsappend(_parse(source, state, verbose, nested + 1,
  File "/opt/python/3.9-dev/lib/python3.9/sre_parse.py", line 834, in _parse
    p = _parse_sub(source, state, sub_verbose, nested + 1)
  File "/opt/python/3.9-dev/lib/python3.9/sre_parse.py", line 443, in _parse_sub
    itemsappend(_parse(source, state, verbose, nested + 1,
  File "/opt/python/3.9-dev/lib/python3.9/sre_parse.py", line 754, in _parse
    p = _parse_sub(source, state, verbose, nested + 1)
  File "/opt/python/3.9-dev/lib/python3.9/sre_parse.py", line 443, in _parse_sub
    itemsappend(_parse(source, state, verbose, nested + 1,
  File "/opt/python/3.9-dev/lib/python3.9/sre_parse.py", line 831, in _parse
    raise source.error(err.msg, len(name) + 1) from None
re.error: redefinition of group name 'g1' as group 2; was group 1 at position 284

Since the traceback is fully in coverage.py, I expect that the details about urllib3 are irrelevant.

@nedbat
Copy link
Owner

nedbat commented May 11, 2020

Thanks, this was exotic.

  1. https://bugs.python.org/issue40480 describes pathological behavior in fnmatch.
  2. python/cpython@b9c46a2 fixes it, but now if the file pattern has more than one star, the regex has numbered group references in it.
    In 3.8:
>>> fnmatch.translate("*foo*")
'(?s:.*foo.*)\\Z'

In 3.9a6+:

>>> fnmatch.translate("*foo*")
'(?s:(?=(?P<g1>.*?foo))(?P=g1).*)\\Z'
  1. Coverage.py combines multiple fnmatch-produced regexes together to make a larger regex. Now there are two groups named g1 in a single regex. Error.

This only showed up because urllib3's omit setting has two patterns with two asterisks: https://github.com/urllib3/urllib3/blob/master/.coveragerc#L6-L11

Now to figure out what to do about it.

@nedbat nedbat changed the title coverage run fails with a re.error with Python coverage run fails with a re.error with Python 3.9a6+ May 11, 2020
@tim-one
Copy link

tim-one commented May 12, 2020

Ned, I believe this will fix it for you:

python/cpython#20049

Thanks for tracking it down! I'll push that change tonight provided the tests all pass.

@nedbat
Copy link
Owner

nedbat commented May 12, 2020

I can confirm that Tim's change does fix the problem.

@nedbat nedbat closed this as completed May 12, 2020
@nedbat nedbat added the not our bug The problem was elsewhere label May 12, 2020
@pquentin
Copy link
Author

Thanks everyone!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working not our bug The problem was elsewhere
Projects
None yet
Development

No branches or pull requests

3 participants