Running flake8 (with flake8-bugbear installed) using Python 3.12 on a file containing this...
class Foo:
def visit_NameConstant(self):
...
...will cause this DeprecationWarning to be emitted:
flake8-bugbear\bugbear.py:1185: DeprecationWarning: ast.NameConstant is deprecated and will be removed in Python 3.14; use ast.Constant instead
class_type = getattr(ast, class_name, None)
This is because of this line here -- doing getattr(ast, "NameConstant", None) causes a DeprecationWarning to be emitted on Python 3.12:
I think the simplest thing here is just to catch and silence any deprecation warnings that might arise as a result of this getattr() call. (An alternative strategy could be to hardcode a list of AST node names that we know are deprecated, and avoid passing them to the getattr() call. But we'd have to make sure we kept that up to date -- more AST nodes might be deprecated in future Python versions.)
Running flake8 (with flake8-bugbear installed) using Python 3.12 on a file containing this...
...will cause this DeprecationWarning to be emitted:
This is because of this line here -- doing
getattr(ast, "NameConstant", None)
causes a DeprecationWarning to be emitted on Python 3.12:https://github.com/PyCQA/flake8-bugbear/blob/2763a13e6d415d5a2cbda51d126f601ae8215480/bugbear.py#L1185
I think the simplest thing here is just to catch and silence any deprecation warnings that might arise as a result of this
getattr()
call. (An alternative strategy could be to hardcode a list of AST node names that we know are deprecated, and avoid passing them to thegetattr()
call. But we'd have to make sure we kept that up to date -- more AST nodes might be deprecated in future Python versions.)