-
-
Notifications
You must be signed in to change notification settings - Fork 313
Open
Labels
Description
When importing NamedTuple from typing, I'm implementing
class A[T, U](NamedTuple)
data: T
error: U
class B[T](A[T, T])
def __new__(cls, data: T, error: T, message: str | None) -> Self:
return super().__new__(cls, data, error)
def __init__(self, data: T, error: T, message: str) -> None:
super().__init__()
<do something with message>Such that I can do
a, b = B(1, 2)
c, d = B(1, 2, "x")
assert a == c
assert c == d
However in my pre-commit hook I get:
Traceback (most recent call last):
File "/Users/seb/.cache/pre-commit/repouuskz6fg/py_env-python3.12/lib/python3.12/site-packages/pylint/utils/ast_walker.py", line 87, in walk
callback(astroid)
File "/Users/seb/.cache/pre-commit/repouuskz6fg/py_env-python3.12/lib/python3.12/site-packages/pylint/checkers/base/basic_error_checker.py", line 426, in visit_call
self._check_inferred_class_is_abstract(inferred, node)
File "/Users/seb/.cache/pre-commit/repouuskz6fg/py_env-python3.12/lib/python3.12/site-packages/pylint/checkers/base/basic_error_checker.py", line 443, in _check_inferred_class_is_abstract
abstract_methods = _has_abstract_methods(inferred)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/seb/.cache/pre-commit/repouuskz6fg/py_env-python3.12/lib/python3.12/site-packages/pylint/checkers/base/basic_error_checker.py", line 76, in _has_abstract_methods
return len(utils.unimplemented_abstract_methods(node)) > 0
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/seb/.cache/pre-commit/repouuskz6fg/py_env-python3.12/lib/python3.12/site-packages/pylint/checkers/utils.py", line 958, in unimplemented_abstract_methods
for obj in ancestor.values():
^^^^^^^^^^^^^^^^^
File "/Users/seb/.cache/pre-commit/repouuskz6fg/py_env-python3.12/lib/python3.12/site-packages/astroid/nodes/scoped_nodes/mixin.py", line 175, in values
return [self[key] for key in self.keys()]
~~~~^^^^^
File "/Users/seb/.cache/pre-commit/repouuskz6fg/py_env-python3.12/lib/python3.12/site-packages/astroid/nodes/scoped_nodes/mixin.py", line 148, in __getitem__
return self.locals[item][0]
~~~~~~~~~~~~~~~~~^^^
IndexError: list index out of range
concurrent.futures.process._RemoteTraceback:
"""
Traceback (most recent call last):
File "/Users/seb/.cache/pre-commit/repouuskz6fg/py_env-python3.12/lib/python3.12/site-packages/pylint/lint/pylinter.py", line 831, in _check_file
check_astroid_module(ast_node)
File "/Users/seb/.cache/pre-commit/repouuskz6fg/py_env-python3.12/lib/python3.12/site-packages/pylint/lint/pylinter.py", line 1020, in check_astroid_module
retval = self._check_astroid_module(
^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/seb/.cache/pre-commit/repouuskz6fg/py_env-python3.12/lib/python3.12/site-packages/pylint/lint/pylinter.py", line 1072, in _check_astroid_module
walker.walk(node)
File "/Users/seb/.cache/pre-commit/repouuskz6fg/py_env-python3.12/lib/python3.12/site-packages/pylint/utils/ast_walker.py", line 90, in walk
self.walk(child)
File "/Users/seb/.cache/pre-commit/repouuskz6fg/py_env-python3.12/lib/python3.12/site-packages/pylint/utils/ast_walker.py", line 90, in walk
self.walk(child)
File "/Users/seb/.cache/pre-commit/repouuskz6fg/py_env-python3.12/lib/python3.12/site-packages/pylint/utils/ast_walker.py", line 90, in walk
self.walk(child)
File "/Users/seb/.cache/pre-commit/repouuskz6fg/py_env-python3.12/lib/python3.12/site-packages/pylint/utils/ast_walker.py", line 87, in walk
callback(astroid)
File "/Users/seb/.cache/pre-commit/repouuskz6fg/py_env-python3.12/lib/python3.12/site-packages/pylint/checkers/base/basic_error_checker.py", line 426, in visit_call
self._check_inferred_class_is_abstract(inferred, node)
File "/Users/seb/.cache/pre-commit/repouuskz6fg/py_env-python3.12/lib/python3.12/site-packages/pylint/checkers/base/basic_error_checker.py", line 443, in _check_inferred_class_is_abstract
abstract_methods = _has_abstract_methods(inferred)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/seb/.cache/pre-commit/repouuskz6fg/py_env-python3.12/lib/python3.12/site-packages/pylint/checkers/base/basic_error_checker.py", line 76, in _has_abstract_methods
return len(utils.unimplemented_abstract_methods(node)) > 0
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/seb/.cache/pre-commit/repouuskz6fg/py_env-python3.12/lib/python3.12/site-packages/pylint/checkers/utils.py", line 958, in unimplemented_abstract_methods
for obj in ancestor.values():
^^^^^^^^^^^^^^^^^
File "/Users/seb/.cache/pre-commit/repouuskz6fg/py_env-python3.12/lib/python3.12/site-packages/astroid/nodes/scoped_nodes/mixin.py", line 175, in values
return [self[key] for key in self.keys()]
~~~~^^^^^
File "/Users/seb/.cache/pre-commit/repouuskz6fg/py_env-python3.12/lib/python3.12/site-packages/astroid/nodes/scoped_nodes/mixin.py", line 148, in __getitem__
return self.locals[item][0]
~~~~~~~~~~~~~~~~~^^^
IndexError: list index out of range
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/Users/seb/.pyenv/versions/3.12.8/lib/python3.12/concurrent/futures/process.py", line 264, in _process_worker
r = call_item.fn(*call_item.args, **call_item.kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/seb/.pyenv/versions/3.12.8/lib/python3.12/concurrent/futures/process.py", line 213, in _process_chunk
return [fn(*args) for args in chunk]
^^^^^^^^^
File "/Users/seb/.cache/pre-commit/repouuskz6fg/py_env-python3.12/lib/python3.12/site-packages/pylint/lint/parallel.py", line 79, in _worker_check_single_file
_worker_linter.check_single_file_item(file_item)
File "/Users/seb/.cache/pre-commit/repouuskz6fg/py_env-python3.12/lib/python3.12/site-packages/pylint/lint/pylinter.py", line 740, in check_single_file_item
self._check_file(self.get_ast, check_astroid_module, file)
File "/Users/seb/.cache/pre-commit/repouuskz6fg/py_env-python3.12/lib/python3.12/site-packages/pylint/lint/pylinter.py", line 833, in _check_file
raise astroid.AstroidError from e
astroid.exceptions.AstroidError
"""
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/Users/seb/.cache/pre-commit/repouuskz6fg/py_env-python3.12/bin/pylint", line 8, in <module>
sys.exit(run_pylint())
^^^^^^^^^^^^
File "/Users/seb/.cache/pre-commit/repouuskz6fg/py_env-python3.12/lib/python3.12/site-packages/pylint/__init__.py", line 34, in run_pylint
PylintRun(argv or sys.argv[1:])
File "/Users/seb/.cache/pre-commit/repouuskz6fg/py_env-python3.12/lib/python3.12/site-packages/pylint/lint/run.py", line 240, in __init__
linter.check(args)
File "/Users/seb/.cache/pre-commit/repouuskz6fg/py_env-python3.12/lib/python3.12/site-packages/pylint/lint/pylinter.py", line 679, in check
check_parallel(
File "/Users/seb/.cache/pre-commit/repouuskz6fg/py_env-python3.12/lib/python3.12/site-packages/pylint/lint/parallel.py", line 162, in check_parallel
) in executor.map(_worker_check_single_file, files):
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/seb/.pyenv/versions/3.12.8/lib/python3.12/concurrent/futures/process.py", line 636, in _chain_from_iterable_of_lists
for element in iterable:
^^^^^^^^
File "/Users/seb/.pyenv/versions/3.12.8/lib/python3.12/concurrent/futures/_base.py", line 619, in result_iterator
yield _result_or_cancel(fs.pop())
^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/seb/.pyenv/versions/3.12.8/lib/python3.12/concurrent/futures/_base.py", line 317, in _result_or_cancel
return fut.result(timeout)
^^^^^^^^^^^^^^^^^^^
File "/Users/seb/.pyenv/versions/3.12.8/lib/python3.12/concurrent/futures/_base.py", line 456, in result
return self.__get_result()
^^^^^^^^^^^^^^^^^^^
File "/Users/seb/.pyenv/versions/3.12.8/lib/python3.12/concurrent/futures/_base.py", line 401, in __get_result
raise self._exception
astroid.exceptions.AstroidError
This occurs both on 3.3.9 and 3.3.10.
Furthermore, when I import NamedTuple via a detour, e.g. from pandas.io.parsers.readers, the error does not occur.
Reactions are currently unavailable