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

0.5.12: regression EdgeCaseError: astAssign.targets[0] is of type <class 'ast.Subscript'> #190

Closed
ssbarnea opened this issue Dec 16, 2024 · 14 comments · Fixed by #191
Closed

Comments

@ssbarnea
Copy link

While trying to update from 0.5.9 to 0.5.12, i faced a runtime exception on https://github.com/ansible/ansible-dev-tools repository.

Traceback (most recent call last):
  File "/Users/ssbarnea/.cache/pre-commit/repo9uz5ky6k/py_env-3.10/bin/pydoclint", line 8, in <module>
    sys.exit(main())
  File "/Users/ssbarnea/.cache/pre-commit/repo9uz5ky6k/py_env-3.10/lib/python3.10/site-packages/click/core.py", line 1157, in __call__
    return self.main(*args, **kwargs)
  File "/Users/ssbarnea/.cache/pre-commit/repo9uz5ky6k/py_env-3.10/lib/python3.10/site-packages/click/core.py", line 1078, in main
    rv = self.invoke(ctx)
  File "/Users/ssbarnea/.cache/pre-commit/repo9uz5ky6k/py_env-3.10/lib/python3.10/site-packages/click/core.py", line 1434, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/Users/ssbarnea/.cache/pre-commit/repo9uz5ky6k/py_env-3.10/lib/python3.10/site-packages/click/core.py", line 783, in invoke
    return __callback(*args, **kwargs)
  File "/Users/ssbarnea/.cache/pre-commit/repo9uz5ky6k/py_env-3.10/lib/python3.10/site-packages/click/decorators.py", line 33, in new_func
    return f(get_current_context(), *args, **kwargs)
  File "/Users/ssbarnea/.cache/pre-commit/repo9uz5ky6k/py_env-3.10/lib/python3.10/site-packages/pydoclint/main.py", line 410, in main
    violationsInAllFiles: dict[str, list[Violation]] = _checkPaths(
  File "/Users/ssbarnea/.cache/pre-commit/repo9uz5ky6k/py_env-3.10/lib/python3.10/site-packages/pydoclint/main.py", line 585, in _checkPaths
    violationsInThisFile: list[Violation] = _checkFile(
  File "/Users/ssbarnea/.cache/pre-commit/repo9uz5ky6k/py_env-3.10/lib/python3.10/site-packages/pydoclint/main.py", line 673, in _checkFile
    visitor.visit(tree)
  File "/Users/ssbarnea/.config/uv/python/cpython-3.10.15-macos-aarch64-none/lib/python3.10/ast.py", line 418, in visit
    return visitor(node)
  File "/Users/ssbarnea/.config/uv/python/cpython-3.10.15-macos-aarch64-none/lib/python3.10/ast.py", line 426, in generic_visit
    self.visit(item)
  File "/Users/ssbarnea/.config/uv/python/cpython-3.10.15-macos-aarch64-none/lib/python3.10/ast.py", line 418, in visit
    return visitor(node)
  File "/Users/ssbarnea/.cache/pre-commit/repo9uz5ky6k/py_env-3.10/lib/python3.10/site-packages/pydoclint/visitor.py", line 106, in visit_ClassDef
    checkClassAttributesAgainstClassDocstring(
  File "/Users/ssbarnea/.cache/pre-commit/repo9uz5ky6k/py_env-3.10/lib/python3.10/site-packages/pydoclint/utils/visitor_helper.py", line 46, in checkClassAttributesAgainstClassDocstring
    actualArgs: ArgList = extractClassAttributesFromNode(
  File "/Users/ssbarnea/.cache/pre-commit/repo9uz5ky6k/py_env-3.10/lib/python3.10/site-packages/pydoclint/utils/visitor_helper.py", line 178, in extractClassAttributesFromNode
    atl.extend(ArgList.fromAstAssign(itm).infoList)
  File "/Users/ssbarnea/.cache/pre-commit/repo9uz5ky6k/py_env-3.10/lib/python3.10/site-packages/pydoclint/utils/arg.py", line 234, in fromAstAssign
    raise EdgeCaseError(
pydoclint.utils.edge_case_error.EdgeCaseError: astAssign.targets[0] is of type <class 'ast.Subscript'>

I am still trying to figure out what is causing it as the output is not really very useful.

@ssbarnea
Copy link
Author

Update: it seems this this problem originates from another place, probably a dependency of pydoclint that was recently released is causing it. It does reproduce with last releases and multiple versions of python too.

@jsh9
Copy link
Owner

jsh9 commented Dec 16, 2024

Thanks for reporting! Let me try to reproduce this error with your repo.

@ssbarnea
Copy link
Author

Locally I no longer can run pydoclint due to the raised bug and I tried on two different machines: macos and ubuntu, both arm64 and using python installed using mise. Still, as you probably seen, on CI it works. I am starting to suspect something related to either pre-commit, uv or mise being involved here.

@jsh9
Copy link
Owner

jsh9 commented Dec 17, 2024

Hi @ssbarnea , I was unable to reproduce this issue locally either. Could you try it in a fresh local env? Or could you find out which line of code in the repo caused this issue? (If you look further than "Traceback (most recent call last)" there may be such info?)

@mvadari
Copy link

mvadari commented Dec 18, 2024

I am also recently running into this issue, despite not changing my pydoclint version (0.5.7). It is fine in CI and when I run pydoclint but fails in flake8.

@jsh9
Copy link
Owner

jsh9 commented Dec 18, 2024

I am also recently running into this issue, despite not changing my pydoclint version (0.5.7). It is fine in CI and when I run pydoclint but fails in flake8.

I probably need more information to reproduce this issue, because when I ran ansible-dev-tools locally, I saw no errors.

@mvadari
Copy link

mvadari commented Dec 18, 2024

I am also recently running into this issue, despite not changing my pydoclint version (0.5.7). It is fine in CI and when I run pydoclint but fails in flake8.

I probably need more information to reproduce this issue, because when I ran ansible-dev-tools locally, I saw no errors.

This is the PR where I had the issue: XRPLF/xrpl-py#749

Reproduction:

poetry install
poetry run flake8

Running on Mac M1

@jsh9
Copy link
Owner

jsh9 commented Dec 19, 2024

Hi @mvadari ,

I tried your steps, and I still couldn't see the issue. poetry run flake8 seemed to run without issues. (I tried in Python 3.9, 3.10, 3.11, 3.12, and 3.13.)

So the issue may be some dependencies in your existing environment clashes with pydoclint. And the reason why things work in CI (as well as on my computer) is that every time pydoclint is run in a fresh environment. (When I run it on your repo on my computer, it's in fresh environments also.)

@ssbarnea
Copy link
Author

I am unable to reproduce on linux but on macos m1 seems to happen with any python blend i tried. I kinda doubt is its dependencies as it runs via pre-commit with only these:

❯ pip freeze
click==8.1.7
docstring_parser_fork==0.0.9
pydoclint @ file:///Users/ssbarnea/.cache/pre-commit/repo05xijrt5

I was failing on a file that was not even tracked under git, part of a test venv,

foo/lib/python3.13/site-packages/pip/_internal/cli/cmdoptions.py

I removed the folder and now is passing, still I am sure that the issue is real. Sadly, too late as I removed the folder.

@mvadari
Copy link

mvadari commented Dec 19, 2024

Hi @mvadari ,

I tried your steps, and I still couldn't see the issue. poetry run flake8 seemed to run without issues. (I tried in Python 3.9, 3.10, 3.11, 3.12, and 3.13.)

So the issue may be some dependencies in your existing environment clashes with pydoclint. And the reason why things work in CI (as well as on my computer) is that every time pydoclint is run in a fresh environment. (When I run it on your repo on my computer, it's in fresh environments also.)

@jsh9 I had this issue with a fresh install too (I also thought it might be some other dependency).

Seems like based on @ssbarnea's comment that it's at least a Mac (if not M1)-specific issue.

@jsh9
Copy link
Owner

jsh9 commented Dec 20, 2024

OK, so I found the issue thanks to @ssbarnea 's clue (foo/lib/python3.13/site-packages/pip/_internal/cli/cmdoptions.py). It's this file: https://github.com/pypa/pip/blob/3b91f42e461de3f23e9bed46a8c5695435f930fb/src/pip/_internal/cli/cmdoptions.py and it's indeed causing that issue in pydoclint.

I have a PR to fix it.

That said, an separate (orthogonal) issue is: why on your local machines would your test framework (tox or poetry) inspect unrelated files. I don't have an answer for this. Maybe it's a regression from some external dependencies. (Btw my computer also has Apple M chips, so maybe OS isn't the culprit here.)

@jsh9 jsh9 closed this as completed in #191 Dec 20, 2024
@jsh9
Copy link
Owner

jsh9 commented Dec 20, 2024

The PR is merged, and the change will be shipped with the new version (0.5.13), which will come out in a few hours. (I have another thing to include into the new version.)

@jsh9
Copy link
Owner

jsh9 commented Dec 20, 2024

0.5.13 is published to pypi.

@mvadari
Copy link

mvadari commented Dec 20, 2024

The fix works for me now, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants