From a2159c801c2706b6dbf01f73be9bc043f3ec9707 Mon Sep 17 00:00:00 2001 From: Robin Jarry Date: Wed, 24 Jan 2024 13:50:41 +0100 Subject: [PATCH] tox: fix lint with python 3.12 Fix the following error when running pylint with python 3.12: Exception on node ImportFrom in file 'cffi/build.py' Traceback (most recent call last): File ".../python3.12/site-packages/pylint/checkers/imports.py", line 846, in _get_imported_module return importnode.do_import_module(modname) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File ".../python3.12/site-packages/astroid/nodes/_base_nodes.py", line 146, in do_import_module return mymodule.import_module( ^^^^^^^^^^^^^^^^^^^^^^^ File ".../python3.12/site-packages/astroid/nodes/scoped_nodes/scoped_nodes.py", line 530, in import_module return AstroidManager().ast_from_module_name( ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File ".../python3.12/site-packages/astroid/manager.py", line 246, in ast_from_module_name return self.ast_from_file(found_spec.location, modname, fallback=False) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File ".../python3.12/site-packages/astroid/manager.py", line 138, in ast_from_file return AstroidBuilder(self).file_build(filepath, modname) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File ".../python3.12/site-packages/astroid/builder.py", line 144, in file_build module, builder = self._data_build(data, modname, path) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File ".../python3.12/site-packages/astroid/builder.py", line 204, in _data_build module = builder.visit_module(node, modname, node_file, package) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File ".../python3.12/site-packages/astroid/rebuilder.py", line 254, in visit_module [self.visit(child, newnode) for child in node.body], ^^^^^^^^^^^^^^^^^^^^^^^^^^ File ".../python3.12/site-packages/astroid/rebuilder.py", line 609, in visit visit_method = getattr(self, visit_name) ^^^^^^^^^^^^^^^^^^^^^^^^^ AttributeError: 'TreeRebuilder' object has no attribute 'visit_typealias' Update all lint and format dependencies to their latest stable releases. Ignore the new use-implicit-booleaness-not-comparison-to-string and use-implicit-booleaness-not-comparison-to-zero pylint rules. Use the correct Hashable reference from collections.abc instead of the deprecated typing alias. Signed-off-by: Robin Jarry --- .github/workflows/ci.yml | 2 ++ libyang/keyed_list.py | 3 ++- pylintrc | 2 ++ tox.ini | 18 +++++++++++------- 4 files changed, 17 insertions(+), 8 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 9cfbb845..4c308738 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -39,6 +39,8 @@ jobs: toxenv: py310 - python: "3.11" toxenv: py311 + - python: "3.12" + toxenv: py312 - python: pypy3.9 toxenv: pypy3 steps: diff --git a/libyang/keyed_list.py b/libyang/keyed_list.py index 02b030fa..1a98af32 100644 --- a/libyang/keyed_list.py +++ b/libyang/keyed_list.py @@ -1,8 +1,9 @@ # Copyright (c) 2020 6WIND S.A. # SPDX-License-Identifier: MIT +from collections.abc import Hashable import copy -from typing import Any, Hashable, Iterable, Optional, Tuple, Union +from typing import Any, Iterable, Optional, Tuple, Union # ------------------------------------------------------------------------------------- diff --git a/pylintrc b/pylintrc index 97a7cec1..16a9f0ae 100644 --- a/pylintrc +++ b/pylintrc @@ -77,6 +77,8 @@ disable= too-many-return-statements, too-many-statements, unused-argument, + use-implicit-booleaness-not-comparison-to-string, + use-implicit-booleaness-not-comparison-to-zero, wrong-import-order, [REPORTS] diff --git a/tox.ini b/tox.ini index f8e3c972..9fd15d15 100644 --- a/tox.ini +++ b/tox.ini @@ -1,5 +1,5 @@ [tox] -envlist = format,lint,py{36,37,38,39,310,311,py3,3},lydevel,coverage +envlist = format,lint,py{36,37,38,39,310,311,312,py3,3},lydevel,coverage skip_missing_interpreters = true isolated_build = true distdir = {toxinidir}/dist @@ -36,8 +36,8 @@ basepython = python3 description = Format python code using isort and black. changedir = . deps = - black~=23.1.0 - isort~=5.12.0 + black~=23.12.1 + isort~=5.13.2 skip_install = true install_command = python3 -m pip install {opts} {packages} allowlist_externals = @@ -52,10 +52,14 @@ basepython = python3 description = Run coding style checks. changedir = . deps = - black~=23.1.0 - flake8~=6.0.0 - isort~=5.12.0 - pylint~=2.16.2 + astroid~=3.0.2 + black~=23.12.1 + flake8~=7.0.0 + isort~=5.13.2 + pycodestyle~=2.11.1 + pyflakes~=3.2.0 + pylint~=3.0.3 + setuptools~=69.0.3 allowlist_externals = /bin/sh /usr/bin/sh