Skip to content

pyupgrade fails with 3.14.2 (similar as previously seen issue) with TypeError #1049

@kratsg

Description

@kratsg

#1038 with a fix in #1040 . In pyhf/pyhf-tutorial#115 - we observe uvx pre-commit run -a fail with CPython == 3.14.2 as below:

Run uvx pre-commit run --all-files
  uvx pre-commit run --all-files
  shell: /usr/bin/bash -e {0}
  env:
    pythonLocation: /opt/hostedtoolcache/Python/3.14.2/x64
    PKG_CONFIG_PATH: /opt/hostedtoolcache/Python/3.14.2/x64/lib/pkgconfig
    Python_ROOT_DIR: /opt/hostedtoolcache/Python/3.14.2/x64
    Python2_ROOT_DIR: /opt/hostedtoolcache/Python/3.14.2/x64
    Python3_ROOT_DIR: /opt/hostedtoolcache/Python/3.14.2/x64
    LD_LIBRARY_PATH: /opt/hostedtoolcache/Python/3.14.2/x64/lib
    UV_PYTHON_INSTALL_DIR: /home/runner/work/_temp/uv-python-dir
    UV_CACHE_DIR: /home/runner/work/_temp/setup-uv-cache
Downloading virtualenv (5.7MiB)
 Downloaded virtualenv
Installed 9 packages in 7ms
[INFO] Initializing environment for https://github.com/pre-commit/pre-commit-hooks.
[INFO] Initializing environment for https://github.com/asottile/pyupgrade.
[INFO] Initializing environment for https://github.com/psf/black-pre-commit-mirror.
[INFO] Initializing environment for https://github.com/psf/black-pre-commit-mirror:.[jupyter].
[INFO] Initializing environment for https://github.com/codespell-project/codespell.
[INFO] Initializing environment for https://github.com/nbQA-dev/nbQA.
[INFO] Initializing environment for https://github.com/nbQA-dev/nbQA:pyupgrade==3.14.0.
[INFO] Initializing environment for https://github.com/nbQA-dev/nbQA:isort==5.11.4.
[INFO] Installing environment for https://github.com/pre-commit/pre-commit-hooks.
[INFO] Once installed this environment will be reused.
[INFO] This may take a few minutes...
[INFO] Installing environment for https://github.com/asottile/pyupgrade.
[INFO] Once installed this environment will be reused.
[INFO] This may take a few minutes...
[INFO] Installing environment for https://github.com/psf/black-pre-commit-mirror.
[INFO] Once installed this environment will be reused.
[INFO] This may take a few minutes...
[INFO] Installing environment for https://github.com/codespell-project/codespell.
[INFO] Once installed this environment will be reused.
[INFO] This may take a few minutes...
[INFO] Installing environment for https://github.com/nbQA-dev/nbQA.
[INFO] Once installed this environment will be reused.
[INFO] This may take a few minutes...
[INFO] Installing environment for https://github.com/nbQA-dev/nbQA.
[INFO] Once installed this environment will be reused.
[INFO] This may take a few minutes...
check for added large files..............................................Passed
check for case conflicts.................................................Passed
check for merge conflicts................................................Passed
check for broken symlinks............................(no files to check)Skipped
check json...............................................................Passed
check yaml...............................................................Passed
check toml...............................................................Passed
check xml................................................................Passed
debug statements (python)................................................Passed
fix end of files.........................................................Passed
mixed line ending........................................................Passed
trim trailing whitespace.................................................Passed
pyupgrade................................................................Failed
- hook id: pyupgrade
- exit code: 1

Traceback (most recent call last):
  File "/home/runner/.cache/pre-commit/repobaotte8o/py_env-python3.14/bin/pyupgrade", line 7, in <module>
    sys.exit(main())
             ~~~~^^
  File "/home/runner/.cache/pre-commit/repobaotte8o/py_env-python3.14/lib/python3.14/site-packages/pyupgrade/_main.py", line 393, in main
    ret |= _fix_file(filename, args)
           ~~~~~~~~~^^^^^^^^^^^^^^^^
  File "/home/runner/.cache/pre-commit/repobaotte8o/py_env-python3.14/lib/python3.14/site-packages/pyupgrade/_main.py", line 327, in _fix_file
    contents_text = _fix_tokens(contents_text)
  File "/home/runner/.cache/pre-commit/repobaotte8o/py_env-python3.14/lib/python3.14/site-packages/pyupgrade/_main.py", line 297, in _fix_tokens
    tokenize.cookie_re.match(token.src)
    ~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^
TypeError: cannot use a bytes pattern on a string-like object

black-jupyter............................................................Passed
codespell................................................................Passed
nbqa-pyupgrade...........................................................Failed
- hook id: nbqa-pyupgrade
- exit code: 1

Traceback (most recent call last):
  File "<frozen runpy>", line 198, in _run_module_as_main
  File "<frozen runpy>", line 88, in _run_code
  File "/home/runner/.cache/pre-commit/repob4wkljoj/py_env-python3.14/lib/python3.14/site-packages/pyupgrade/__main__.py", line 6, in <module>
    raise SystemExit(main())
                     ~~~~^^
  File "/home/runner/.cache/pre-commit/repob4wkljoj/py_env-python3.14/lib/python3.14/site-packages/pyupgrade/_main.py", line 385, in main
    ret |= _fix_file(filename, args)
           ~~~~~~~~~^^^^^^^^^^^^^^^^
  File "/home/runner/.cache/pre-commit/repob4wkljoj/py_env-python3.14/lib/python3.14/site-packages/pyupgrade/_main.py", line 327, in _fix_file
    contents_text = _fix_tokens(contents_text)
  File "/home/runner/.cache/pre-commit/repob4wkljoj/py_env-python3.14/lib/python3.14/site-packages/pyupgrade/_main.py", line 297, in _fix_tokens
    tokenize.cookie_re.match(token.src)
    ~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^
TypeError: cannot use a bytes pattern on a string-like object

nbqa-isort...............................................................Passed
Error: Process completed with exit code 1.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions