jendrikseipp / vulture

Find dead Python code

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Python 3.12: DeprecationWarning: ast.Str is deprecated and will be removed in Python 3.14; use ast.Constant instead

The-Compiler opened this issue · comments

With an x.py such as:

hasattr("", "test")

running Python 3.12.0b2 via python3.12 -Werror -m vulture x.py results in:

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/florian/tmp/vultdeprecation/.venv/lib/python3.12/site-packages/vulture/__main__.py", line 3, in <module>
    main()
  File "/home/florian/tmp/vultdeprecation/.venv/lib/python3.12/site-packages/vulture/core.py", line 725, in main
    vulture.scavenge(config["paths"], exclude=config["exclude"])
  File "/home/florian/tmp/vultdeprecation/.venv/lib/python3.12/site-packages/vulture/core.py", line 289, in scavenge
    self.scan(module_string, filename=module)
  File "/home/florian/tmp/vultdeprecation/.venv/lib/python3.12/site-packages/vulture/core.py", line 256, in scan
    self.visit(node)
  File "/home/florian/tmp/vultdeprecation/.venv/lib/python3.12/site-packages/vulture/core.py", line 681, in visit
    return self.generic_visit(node)
           ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/florian/tmp/vultdeprecation/.venv/lib/python3.12/site-packages/vulture/core.py", line 713, in generic_visit
    self.visit(item)
  File "/home/florian/tmp/vultdeprecation/.venv/lib/python3.12/site-packages/vulture/core.py", line 681, in visit
    return self.generic_visit(node)
           ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/florian/tmp/vultdeprecation/.venv/lib/python3.12/site-packages/vulture/core.py", line 715, in generic_visit
    self.visit(value)
  File "/home/florian/tmp/vultdeprecation/.venv/lib/python3.12/site-packages/vulture/core.py", line 666, in visit
    visitor(node)
  File "/home/florian/tmp/vultdeprecation/.venv/lib/python3.12/site-packages/vulture/core.py", line 528, in visit_Call
    if isinstance(attr_name_arg, ast.Str):
                                 ^^^^^^^
  File "/usr/lib/python3.12/ast.py", line 1787, in __getattr__
    warnings._deprecated(
  File "/usr/lib/python3.12/warnings.py", line 529, in _deprecated
    warn(msg, DeprecationWarning, stacklevel=3)
DeprecationWarning: ast.Str is deprecated and will be removed in Python 3.14; use ast.Constant instead

Thank you for the detailed description, Florian! I'll send a PR for this.

It looks like this was fixed in

commit be8f05d3672794a6dfa7b4f09f5efaa35df9e7e2
Author: Jendrik Seipp <jendrikseipp@gmail.com>
Date:   Fri Oct 6 17:49:12 2023 +0200

    Add support for Python 3.12. (#332)
    
    * Use ast.Constant instead of ast.Str.
    * Bump pytest.

@jendrikseipp mind closing this case?

Good point!