Skip to content

Commit

Permalink
tox: fix lint with python 3.12
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
rjarry committed Jan 24, 2024
1 parent bff1462 commit 3ba82f3
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 8 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ jobs:
toxenv: py310
- python: "3.11"
toxenv: py311
- python: "3.12"
toxenv: py312
- python: pypy3.9
toxenv: pypy3
steps:
Expand Down
3 changes: 2 additions & 1 deletion libyang/keyed_list.py
Original file line number Diff line number Diff line change
@@ -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


# -------------------------------------------------------------------------------------
Expand Down
2 changes: 2 additions & 0 deletions pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
18 changes: 11 additions & 7 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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 =
Expand All @@ -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
Expand Down

0 comments on commit 3ba82f3

Please sign in to comment.