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

AssertionError: Unexpected node type: <class 'ast.Subscript'> on version > 23.2.13 #369

Closed
ecs-jnguyen opened this issue Mar 16, 2023 · 4 comments · Fixed by #370
Closed
Assignees

Comments

@ecs-jnguyen
Copy link

Hi when I use flake8, I'm getting this exception AssertionError: Unexpected node type: <class 'ast.Subscript'>. I notice the error on version 23.2.13 and 23.3.12. When I revert back to 23.1.20 the error goes away.

Stack Trace

Expand
multiprocessing.pool.RemoteTraceback: 
"""
Traceback (most recent call last):
  File "/opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/multiprocessing/pool.py", line 125, in worker
    result = (True, func(*args, **kwds))
  File "/opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/multiprocessing/pool.py", line 48, in mapstar
    return list(map(*args))
  File "/opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/flake8/checker.py", line 621, in _run_checks
    return checker.run_checks()
  File "/opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/flake8/checker.py", line 531, in run_checks
    self.run_ast_checks()
  File "/opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/flake8/checker.py", line 435, in run_ast_checks
    for (line_number, offset, text, _) in runner:
  File "/opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/bugbear.py", line 61, in run
    visitor.visit(self.tree)
  File "/opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/bugbear.py", line 336, in visit
    super().visit(node)
  File "/opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/ast.py", line 407, in visit
    return visitor(node)
  File "/opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/bugbear.py", line 417, in visit_Module
    self.generic_visit(node)
  File "/opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/ast.py", line 415, in generic_visit
    self.visit(item)
  File "/opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/bugbear.py", line 336, in visit
    super().visit(node)
  File "/opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/ast.py", line 407, in visit
    return visitor(node)
  File "/opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/bugbear.py", line 482, in visit_ClassDef
    self.generic_visit(node)
  File "/opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/ast.py", line 415, in generic_visit
    self.visit(item)
  File "/opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/bugbear.py", line 336, in visit
    super().visit(node)
  File "/opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/ast.py", line 407, in visit
    return visitor(node)
  File "/opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/bugbear.py", line 475, in visit_FunctionDef
    self.generic_visit(node)
  File "/opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/ast.py", line 415, in generic_visit
    self.visit(item)
  File "/opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/bugbear.py", line 336, in visit
    super().visit(node)
  File "/opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/ast.py", line 407, in visit
    return visitor(node)
  File "/opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/bugbear.py", line 487, in visit_Try
    self.generic_visit(node)
  File "/opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/ast.py", line 415, in generic_visit
    self.visit(item)
  File "/opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/bugbear.py", line 336, in visit
    super().visit(node)
  File "/opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/ast.py", line 407, in visit
    return visitor(node)
  File "/opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/bugbear.py", line 360, in visit_ExceptHandler
    names = [_to_name_str(e) for e in good_handlers]
  File "/opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/bugbear.py", line 360, in <listcomp>
    names = [_to_name_str(e) for e in good_handlers]
  File "/opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/bugbear.py", line 259, in _to_name_str
    return _to_name_str(node.value) + "." + node.attr
  File "/opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/bugbear.py", line 259, in _to_name_str
    return _to_name_str(node.value) + "." + node.attr
  File "/opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/bugbear.py", line 257, in _to_name_str
    assert isinstance(node, ast.Attribute), f"Unexpected node type: {type(node)}"
AssertionError: Unexpected node type: <class 'ast.Subscript'>
"""

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/opt/hostedtoolcache/Python/3.9.16/x64/bin/flake8", line 8, in <module>
    sys.exit(main())
  File "/opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/flake8/main/cli.py", line 22, in main
    app.run(argv)
  File "/opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/flake8/main/application.py", line 336, in run
    self._run(argv)
  File "/opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/flake8/main/application.py", line 325, in _run
    self.run_checks()
  File "/opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/flake8/main/application.py", line 229, in run_checks
    self.file_checker_manager.run()
  File "/opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/flake8/checker.py", line 250, in run
    self.run_parallel()
  File "/opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/flake8/checker.py", line 217, in run_parallel
    for ret in pool_map:
  File "/opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/multiprocessing/pool.py", line 448, in <genexpr>
    return (item for chunk in result for item in chunk)
  File "/opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/multiprocessing/pool.py", line 870, in next
    raise value
AssertionError: Unexpected node type: <class 'ast.Subscript'>
@FozzieHi
Copy link
Contributor

Thanks for the report. Does this happen when you run flake8 against a specific file, or is it a more general issue?

@JelleZijlstra
Copy link
Collaborator

Seems to be related to except handlers, I'll take a look. Possibly happens on something like except a[0].b:.

@JelleZijlstra JelleZijlstra self-assigned this Mar 16, 2023
@ecs-jnguyen
Copy link
Author

I'm running it on an entire repository

@ecs-jnguyen
Copy link
Author

ecs-jnguyen commented Mar 16, 2023

I found the issue file. I believe you are right @FozzieHi, I see there's a block that looks like this. When I updated that line the error went away:

something = ...
try:
    ...
except something["abc"].exception.Exception:
    ...

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