question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

nox-poetry crashes with `TypeError: slice indices must be integers or None or have an __index__ method`

See original GitHub issue

nox-poetry crashes in the GA workflow when parsing requirements with packaging < 21.1 and pyparsing >= 3:

  File ".../python3.9/site-packages/packaging/requirements.py", line 81, in <lambda>
    lambda s, l, t: Marker(s[t._original_start : t._original_end])
TypeError: slice indices must be integers or None or have an __index__ method

The latest version for packaging is not installed because Poetry depends on packaging < 21.0.

There is a workaround for this, adding pyparsing < 3 to .github/workflows/constraints.txt.

A better fix would be to install Poetry and Nox in separate environments, using a tool like pipx.

Traceback
❯ nox -s mypy
nox > Running session mypy-3.9
nox > Creating virtual environment (virtualenv) using python3.9 in .nox/mypy-3-9
nox > poetry build --format=wheel
nox > pip uninstall --yes file:///Users/cjolowicz/Code/github.com/cjolowicz/cutty/dist/cutty-0.15.0-py3-none-any.whl
nox > poetry export --format=requirements.txt --dev --without-hashes
nox > Session mypy-3.9 raised exception TypeError('slice indices must be integers or None or have an __index__ method')
Traceback (most recent call last):
  File "/Users/cjolowicz/.local/pipx/venvs/nox/lib/python3.9/site-packages/nox/sessions.py", line 626, in execute
    self.func(session)
  File "/Users/cjolowicz/.local/pipx/venvs/nox/lib/python3.9/site-packages/nox/_decorators.py", line 54, in __call__
    return self.func(*args, **kwargs)
  File "/Users/cjolowicz/.local/pipx/venvs/nox/lib/python3.9/site-packages/nox_poetry/sessions.py", line 43, in wrapper
    function(proxy, *_args, **_kwargs)
  File "/Users/cjolowicz/Code/github.com/cjolowicz/cutty/noxfile.py", line 128, in mypy
    session.install(".")
  File "/Users/cjolowicz/.local/pipx/venvs/nox/lib/python3.9/site-packages/nox_poetry/sessions.py", line 290, in install
    return self.poetry.install(*args, **kwargs)
  File "/Users/cjolowicz/.local/pipx/venvs/nox/lib/python3.9/site-packages/nox_poetry/sessions.py", line 149, in install
    requirements = self.export_requirements()
  File "/Users/cjolowicz/.local/pipx/venvs/nox/lib/python3.9/site-packages/nox_poetry/sessions.py", line 224, in export_requirements
    constraints = to_constraints(self.poetry.export())
  File "/Users/cjolowicz/.local/pipx/venvs/nox/lib/python3.9/site-packages/nox_poetry/sessions.py", line 90, in to_constraints
    return "\n".join(_to_constraints())
  File "/Users/cjolowicz/.local/pipx/venvs/nox/lib/python3.9/site-packages/nox_poetry/sessions.py", line 86, in _to_constraints
    constraint = to_constraint(requirement, line)
  File "/Users/cjolowicz/.local/pipx/venvs/nox/lib/python3.9/site-packages/nox_poetry/sessions.py", line 68, in to_constraint
    requirement = Requirement(requirement_string)
  File "/Users/cjolowicz/.local/pipx/venvs/nox/lib/python3.9/site-packages/packaging/requirements.py", line 113, in __init__
    req = REQUIREMENT.parseString(requirement_string)
  File "/Users/cjolowicz/.local/pipx/venvs/nox/lib/python3.9/site-packages/pyparsing/core.py", line 1100, in parse_string
    loc, tokens = self._parse(instring, 0)
  File "/Users/cjolowicz/.local/pipx/venvs/nox/lib/python3.9/site-packages/pyparsing/core.py", line 790, in _parseNoCache
    loc, tokens = self.parseImpl(instring, pre_loc, doActions)
  File "/Users/cjolowicz/.local/pipx/venvs/nox/lib/python3.9/site-packages/pyparsing/core.py", line 3810, in parseImpl
    loc, exprtokens = e._parse(instring, loc, doActions)
  File "/Users/cjolowicz/.local/pipx/venvs/nox/lib/python3.9/site-packages/pyparsing/core.py", line 790, in _parseNoCache
    loc, tokens = self.parseImpl(instring, pre_loc, doActions)
  File "/Users/cjolowicz/.local/pipx/venvs/nox/lib/python3.9/site-packages/pyparsing/core.py", line 4024, in parseImpl
    return e._parse(
  File "/Users/cjolowicz/.local/pipx/venvs/nox/lib/python3.9/site-packages/pyparsing/core.py", line 790, in _parseNoCache
    loc, tokens = self.parseImpl(instring, pre_loc, doActions)
  File "/Users/cjolowicz/.local/pipx/venvs/nox/lib/python3.9/site-packages/pyparsing/core.py", line 3810, in parseImpl
    loc, exprtokens = e._parse(instring, loc, doActions)
  File "/Users/cjolowicz/.local/pipx/venvs/nox/lib/python3.9/site-packages/pyparsing/core.py", line 790, in _parseNoCache
    loc, tokens = self.parseImpl(instring, pre_loc, doActions)
  File "/Users/cjolowicz/.local/pipx/venvs/nox/lib/python3.9/site-packages/pyparsing/core.py", line 4854, in parseImpl
    loc, tokens = self_expr._parse(instring, loc, doActions, callPreParse=False)
  File "/Users/cjolowicz/.local/pipx/venvs/nox/lib/python3.9/site-packages/pyparsing/core.py", line 790, in _parseNoCache
    loc, tokens = self.parseImpl(instring, pre_loc, doActions)
  File "/Users/cjolowicz/.local/pipx/venvs/nox/lib/python3.9/site-packages/pyparsing/core.py", line 3810, in parseImpl
    loc, exprtokens = e._parse(instring, loc, doActions)
  File "/Users/cjolowicz/.local/pipx/venvs/nox/lib/python3.9/site-packages/pyparsing/core.py", line 827, in _parseNoCache
    tokens = fn(instring, tokens_start, ret_tokens)
  File "/Users/cjolowicz/.local/pipx/venvs/nox/lib/python3.9/site-packages/pyparsing/core.py", line 283, in wrapper
    ret = func(*args[limit:])
  File "/Users/cjolowicz/.local/pipx/venvs/nox/lib/python3.9/site-packages/packaging/requirements.py", line 81, in <lambda>
    lambda s, l, t: Marker(s[t._original_start : t._original_end])
TypeError: slice indices must be integers or None or have an __index__ method
nox > Session mypy-3.9 failed.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
laydaycommented, Nov 8, 2021

Just FYI the linked PR is unrelated. This is a regression in pyparsing 3.0.5 and cutting a new packaging release without excluding 3.0.5 will break packaging for everyone (!).

0reactions
cjolowiczcommented, Nov 10, 2021

Thanks for reporting back @heiderich

Read more comments on GitHub >

github_iconTop Results From Across the Web

slice indices must be integers or None or have an __index__ ...
Hi, I am a little bit lost. Since about 1 week all of my nox CI jobs suddenly started failing. No new poetry...
Read more >
TypeError: slice indices must be integers or None or have an ...
The Python TypeError: slice indices must be integers or None or have an index method occurs when we use a non-integer value for...
Read more >
TypeError slice indices must be integers or none or have an ...
Here, line 4 of the code I.e print(MyList[0:'2']) will throw an error because the ending index value is a string type and not...
Read more >
python 3.x - TypeError: slice indices must be integers or None ...
In 3.x, int/int gives a float. which is not an int. >>> 3/2 1.5. so your line 15 half = len(m)/2. makes half...
Read more >
Slice indices must be integers or None or have an __index
The “TypeError: slice indices must be integers or None or have an __index__ method” error is raised when you try to slice a...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found