asottile/add-trailing-comma

python 3.9.1 assertion error on Windows 10

infinity-plus opened this issue · 7 comments

I ran into the following error when committing:
VSCode console output:

> git -c user.useConfigOnly=true commit --quiet --allow-empty-message --file -
Trim Trailing Whitespace.................................................Passed
Fix End of Files.........................................................Passed
Check docstring is first.................................................Passed
Debug Statements (Python)................................................Passed
Fix requirements.txt.................................(no files to check)Skipped
Check for added large files..............................................Passed
Check python ast.........................................................Passed
Check builtin type constructor use.......................................Passed
Check for case conflicts.................................................Passed
Detect Destroyed Symlinks................................................Passed
Check for merge conflicts................................................Passed
Check Yaml...........................................(no files to check)Skipped
Debug Statements (Python)................................................Passed
Detect Private Key.......................................................Passed
fix UTF-8 byte order marker..............................................Passed
Add trailing commas......................................................Failed
- hook id: add-trailing-comma
- exit code: 1

Traceback (most recent call last):
  File "c:\program files\python39\lib\runpy.py", line 197, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "c:\program files\python39\lib\runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "C:\Users\navdh\.cache\pre-commit\repoy6phnb7j\py_env-python3.9\Scripts\add-trailing-comma.EXE\__main__.py", line 7, in <module>
  File "c:\users\navdh\.cache\pre-commit\repoy6phnb7j\py_env-python3.9\lib\site-packages\add_trailing_comma.py", line 498, in main
    ret |= fix_file(filename, args)
  File "c:\users\navdh\.cache\pre-commit\repoy6phnb7j\py_env-python3.9\lib\site-packages\add_trailing_comma.py", line 470, in fix_file
    contents_text = _fix_src(contents_text, args.py35_plus, args.py36_plus)
  File "c:\users\navdh\.cache\pre-commit\repoy6phnb7j\py_env-python3.9\lib\site-packages\add_trailing_comma.py", line 401, in _fix_src
    tokens, _find_call(call, i, tokens),
  File "c:\users\navdh\.cache\pre-commit\repoy6phnb7j\py_env-python3.9\lib\site-packages\add_trailing_comma.py", line 239, in _find_call
    raise AssertionError('Past end?')
AssertionError: Past end?```

Platform: Windows 10 21H1 OS Build 19043.906
Python Version: 3.9.1

My config:

repos:
    - repo: https://github.com/pre-commit/pre-commit-hooks
      rev: v3.4.0
      hooks:
          - id: trailing-whitespace
          - id: end-of-file-fixer
          - id: check-docstring-first
          - id: debug-statements
          - id: requirements-txt-fixer
          - id: check-added-large-files
          - id: check-ast
          - id: check-builtin-literals
          - id: check-case-conflict
          - id: destroyed-symlinks
          - id: check-merge-conflict
          - id: check-yaml
          - id: debug-statements
          - id: detect-private-key
          - id: fix-byte-order-marker
    - repo: https://github.com/asottile/add-trailing-comma
      rev: v2.0.1
      hooks:
          - id: add-trailing-comma
            args: [--py36-plus]

can you share a code sample? also can you reproduce on 2.1.0 ?

actually, this looks like a dupe of #106 which was fixed in >=2.0.2 -- you're running 2.0.1

actually, this looks like a dupe of #106 which was fixed in >=2.0.2 -- you're running 2.0.1

I actually read that Issue before creating new, Just installed pre-commit today, here's what pip freeze shows:
pre-commit==2.12.0

yeah but see how your issue shows rev: v2.0.1 ?

okay, I get it, installed add-trailing-comma from pip, and it installed v2.0.1
also tried installing with
pip install git+https://github.com/asottile/add-trailing-comma
still it installs v2.0.1

yeah you don't need to install it from git or with pip, pre-commit installs its own copy based on what you have configured in your .pre-commit-config.yaml

since that value says v2.0.1 then that's what it will use. you can update that value automatically using pre-commit autoupdate

Thank you, fixed :D
My bad, sorry for trouble