astroid
astroid copied to clipboard
`test_no_user_warning` assumes pip is available
I'm packaging your module as an rpm package so I'm using the typical PEP517 based build, install and test cycle used on building packages from non-root account.
python3 -sBm build -w --no-isolation- because I'm calling
buildwith--no-isolationI'm using during all processes only locally installed modules - install .whl file in </install/prefix> using
installermodule - run pytest with $PYTHONPATH pointing to sitearch and sitelib inside </install/prefix>
- build is performed in env which is
cut off from access to the public network(pytest is executed with-m "not network")
Here is pytest output:
+ PYTHONPATH=/home/tkloczko/rpmbuild/BUILDROOT/python-astroid-3.1.0-2.fc36.x86_64/usr/lib64/python3.9/site-packages:/home/tkloczko/rpmbuild/BUILDROOT/python-astroid-3.1.0-2.fc36.x86_64/usr/lib/python3.9/site-packages
+ /usr/bin/pytest -ra -m 'not network'
==================================================================================== test session starts ====================================================================================
platform linux -- Python 3.9.18, pytest-8.1.1, pluggy-1.4.0
rootdir: /home/tkloczko/rpmbuild/BUILD/astroid-3.1.0
configfile: pyproject.toml
testpaths: tests
plugins: hypothesis-6.99.5, xdist-3.5.0, forked-1.6.0
collected 1679 items / 1 skipped
tests/brain/numpy/test_core_einsumfunc.py ss [ 0%]
tests/brain/numpy/test_core_fromnumeric.py s [ 0%]
tests/brain/numpy/test_core_function_base.py s [ 0%]
tests/brain/numpy/test_core_multiarray.py sssss [ 0%]
tests/brain/numpy/test_core_numeric.py sssss [ 0%]
tests/brain/numpy/test_core_numerictypes.py sssssss.. [ 1%]
tests/brain/numpy/test_core_umath.py ssssssss [ 1%]
tests/brain/numpy/test_ma.py ssss [ 2%]
tests/brain/numpy/test_ndarray.py sss [ 2%]
tests/brain/numpy/test_random_mtrand.py ss [ 2%]
tests/brain/test_argparse.py . [ 2%]
tests/brain/test_attr.py ..... [ 2%]
tests/brain/test_brain.py .s.....s....ss......................................s....s..........................................................x...................... [ 11%]
tests/brain/test_builtin.py .................. [ 12%]
tests/brain/test_ctypes.py ....x........................ [ 13%]
tests/brain/test_dataclasses.py ..............................................................................x... [ 18%]
tests/brain/test_dateutil.py . [ 18%]
tests/brain/test_enum.py ............................. [ 20%]
tests/brain/test_hashlib.py ... [ 20%]
tests/brain/test_multiprocessing.py ... [ 20%]
tests/brain/test_named_tuple.py ....................... [ 22%]
tests/brain/test_nose.py s [ 22%]
tests/brain/test_pathlib.py .... [ 22%]
tests/brain/test_pytest.py . [ 22%]
tests/brain/test_qt.py sss [ 22%]
tests/brain/test_regex.py ss [ 22%]
tests/brain/test_signal.py ... [ 23%]
tests/brain/test_six.py ssssss [ 23%]
tests/brain/test_ssl.py . [ 23%]
tests/brain/test_threading.py .... [ 23%]
tests/brain/test_typing.py . [ 23%]
tests/brain/test_typing_extensions.py . [ 23%]
tests/brain/test_unittest.py . [ 23%]
tests/test_builder.py .......................................................x.. [ 27%]
tests/test_constraint.py ................................... [ 29%]
tests/test_decorators.py ... [ 29%]
tests/test_filter_statements.py . [ 29%]
tests/test_group_exceptions.py sss [ 29%]
tests/test_helpers.py ............... [ 30%]
tests/test_inference.py ...........................s..............................................................x...........x.....x................................................ [ 40%]
........x...................................................................s.........sss.........................................................x........xx.....................x.. [ 50%]
.x..........................................s......x........................................ [ 56%]
tests/test_inference_calls.py ........................ [ 57%]
tests/test_lookup.py ....................................................... [ 61%]
tests/test_manager.py ....................................F...... [ 63%]
tests/test_modutils.py ................................................s................. [ 67%]
tests/test_nodes.py ...................ssss..........................................................................sssss........................................................... [ 77%]
........................... [ 78%]
tests/test_nodes_lineno.py s...................s... [ 80%]
tests/test_nodes_position.py ... [ 80%]
tests/test_object_model.py x...............x................... [ 82%]
tests/test_objects.py ...................... [ 83%]
tests/test_protocols.py ...............ssssss [ 85%]
tests/test_python3.py .......................... [ 86%]
tests/test_raw_building.py ............. [ 87%]
tests/test_regrtest.py .............ss........... [ 88%]
tests/test_scoped_nodes.py ...............................................................................................ss................................s.s...................... [ 98%]
............. [ 98%]
tests/test_stdlib.py .. [ 98%]
tests/test_transforms.py ......... [ 99%]
tests/test_utils.py ........ [100%]
========================================================================================= FAILURES ==========================================================================================
______________________________________________________________________ IsolatedAstroidManagerTest.test_no_user_warning ______________________________________________________________________
self = <tests.test_manager.IsolatedAstroidManagerTest testMethod=test_no_user_warning>
def test_no_user_warning(self):
mgr = manager.AstroidManager()
with warnings.catch_warnings():
warnings.filterwarnings("error", category=UserWarning)
mgr.ast_from_module_name("setuptools")
> mgr.ast_from_module_name("pip")
tests/test_manager.py:393:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
astroid/manager.py:266: in ast_from_module_name
raise e
astroid/manager.py:211: in ast_from_module_name
found_spec = self.file_from_module_name(modname, context_file)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <astroid.manager.AstroidManager object at 0x7f7a9c889eb0>, modname = 'pip', contextfile = None
def file_from_module_name(
self, modname: str, contextfile: str | None
) -> spec.ModuleSpec:
try:
value = self._mod_file_cache[(modname, contextfile)]
except KeyError:
try:
value = file_info_from_modpath(
modname.split("."), context_file=contextfile
)
except ImportError as e:
# pylint: disable-next=redefined-variable-type
value = AstroidImportError(
"Failed to import module {modname} with error:\n{error}.",
modname=modname,
# we remove the traceback here to save on memory usage (since these exceptions are cached)
error=e.with_traceback(None),
)
self._mod_file_cache[(modname, contextfile)] = value
if isinstance(value, AstroidBuildingError):
# we remove the traceback here to save on memory usage (since these exceptions are cached)
> raise value.with_traceback(None) # pylint: disable=no-member
E astroid.exceptions.AstroidImportError: Failed to import module pip with error:
E No module named pip.
astroid/manager.py:318: AstroidImportError
========================================================================================= XFAILURES =========================================================================================
____________________________________________________________________ TestLenBuiltinInference.test_int_subclass_argument _____________________________________________________________________
args = (<Call l.4 at 0x7f7aa0c26790>,), kwargs = {'context': <astroid.context.InferenceContext object at 0x7f7aa15e5280>}, generator = <generator object Call._infer at 0x7f7aa0eb4c80>
def inner(
*args: _P.args, **kwargs: _P.kwargs
) -> Generator[InferenceResult, None, None]:
generator = func(*args, **kwargs)
try:
> yield next(generator)
E StopIteration
astroid/decorators.py:90: StopIteration
The above exception was the direct cause of the following exception:
self = <tests.brain.test_brain.TestLenBuiltinInference object at 0x7f7aa3a595b0>
@pytest.mark.xfail(reason="Can't use list special astroid fields")
def test_int_subclass_argument(self):
"""I am unable to access the length of an object which
subclasses list"""
node = astroid.extract_node(
"""
class ListSubclass(list):
pass
len(ListSubclass([1,2,3,4,4]))
"""
)
> assert next(node.infer()).as_string() == "5"
tests/brain/test_brain.py:1626:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
astroid/nodes/node_ng.py:170: in infer
for i, result in enumerate(self._infer(context=context, **kwargs)):
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
args = (<Call l.4 at 0x7f7aa0c26790>,), kwargs = {'context': <astroid.context.InferenceContext object at 0x7f7aa15e5280>}, generator = <generator object Call._infer at 0x7f7aa0eb4c80>
def inner(
*args: _P.args, **kwargs: _P.kwargs
) -> Generator[InferenceResult, None, None]:
generator = func(*args, **kwargs)
try:
yield next(generator)
except StopIteration as error:
# generator is empty
if error.args:
raise InferenceError(**error.args[0]) from error
> raise InferenceError(
"StopIteration raised without any error information."
) from error
E astroid.exceptions.InferenceError: StopIteration raised without any error information.
astroid/decorators.py:95: InferenceError
________________________________________________________ test_ctypes_redefined_types_members[c_buffer-bytes-<class 'ctypes.c_char'>] ________________________________________________________
c_type = 'c_buffer', builtin_type = 'bytes', type_code = "<class 'ctypes.c_char'>"
@pytest.mark.parametrize(
"c_type,builtin_type,type_code",
[
("c_bool", "bool", "?"),
("c_byte", "int", "b"),
("c_char", "bytes", "c"),
("c_double", "float", "d"),
pytest.param(
"c_buffer",
"bytes",
"<class 'ctypes.c_char'>",
marks=pytest.mark.xfail(
reason="c_buffer is Uninferable but for now we do not know why"
),
),
("c_float", "float", "f"),
("c_int", "int", "i"),
("c_int16", "int", "h"),
("c_int32", "int", "i"),
("c_int64", "int", "l"),
("c_int8", "int", "b"),
("c_long", "int", "l"),
("c_longdouble", "float", "g"),
("c_longlong", "int", "l"),
("c_short", "int", "h"),
("c_size_t", "int", "L"),
("c_ssize_t", "int", "l"),
("c_ubyte", "int", "B"),
("c_uint", "int", "I"),
("c_uint16", "int", "H"),
("c_uint32", "int", "I"),
("c_uint64", "int", "L"),
("c_uint8", "int", "B"),
("c_ulong", "int", "L"),
("c_ulonglong", "int", "L"),
("c_ushort", "int", "H"),
("c_wchar", "str", "u"),
],
)
def test_ctypes_redefined_types_members(c_type, builtin_type, type_code):
"""Test that the "value" and "_type_" member of each redefined types are
correct.
"""
src = f"""
import ctypes
x=ctypes.{c_type}("toto")
x.value
"""
node = extract_node(src)
assert isinstance(node, nodes.NodeNG)
node_inf = node.inferred()[0]
> assert node_inf.pytype() == f"builtins.{builtin_type}"
E AssertionError: assert Uninferable == 'builtins.bytes'
E + where Uninferable = Uninferable()
E + where Uninferable = Uninferable.pytype
tests/brain/test_ctypes.py:71: AssertionError
_____________________________________________________________________ test_dataclass_non_default_argument_after_default _____________________________________________________________________
@pytest.mark.xfail(reason="Transforms returning Uninferable isn't supported.")
def test_dataclass_non_default_argument_after_default() -> None:
"""Test that a non-default argument after a default argument is not allowed.
This should succeed, but the dataclass brain is a transform
which currently can't return an Uninferable correctly. Therefore, we can't
set the dataclass ClassDef node to be Uninferable currently.
Eventually it can be merged into test_dataclass_with_multiple_inheritance.
"""
impossible = astroid.extract_node(
"""
from dataclasses import dataclass
@dataclass
class BaseParent:
required: bool
@dataclass
class FirstChild(BaseParent):
...
@dataclass
class SecondChild(BaseParent):
optional: bool = False
@dataclass
class ThirdChild:
other: bool = False
@dataclass
class ImpossibleGrandChild(FirstChild, SecondChild, ThirdChild):
...
ImpossibleGrandChild() #@
"""
)
> assert next(impossible.infer()) is Uninferable
E assert <Instance of .ImpossibleGrandChild at 0x140164632786832> is Uninferable
E + where <Instance of .ImpossibleGrandChild at 0x140164632786832> = next(<generator object NodeNG.infer at 0x7f7aa1d00dd0>)
E + where <generator object NodeNG.infer at 0x7f7aa1d00dd0> = <bound method NodeNG.infer of <Call l.24 at 0x7f7a9f465f70>>()
E + where <bound method NodeNG.infer of <Call l.24 at 0x7f7a9f465f70>> = <Call l.24 at 0x7f7a9f465f70>.infer
tests/brain/test_dataclasses.py:1173: AssertionError
________________________________________________________________ test_parse_module_with_invalid_type_comments_does_not_crash ________________________________________________________________
self = <astroid.builder.AstroidBuilder object at 0x7f7a9c545310>
data = '\n# op {\n# name: "AssignAddVariableOp"\n# input_arg {\n# name: "resource"\n# type: DT_RESOURCE\n# }\n#...tr: "dtype"\n# }\n# attr {\n# name: "dtype"\n# type: "type"\n# }\n# is_stateful: true\n# }\na, b = 2\n'
modname = '', path = None
def _data_build(
self, data: str, modname: str, path: str | None
) -> tuple[nodes.Module, rebuilder.TreeRebuilder]:
"""Build tree node from data and add some informations."""
try:
> node, parser_module = _parse_string(
data, type_comments=True, modname=modname
)
astroid/builder.py:181:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
astroid/builder.py:480: in _parse_string
parsed = parser_module.parse(
astroid/_ast.py:30: in parse
return ast.parse(string, type_comments=type_comments)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
source = '\n# op {\n# name: "AssignAddVariableOp"\n# input_arg {\n# name: "resource"\n# type: DT_RESOURCE\n# }\n#...: "dtype"\n# }\n# attr {\n# name: "dtype"\n# type: "type"\n# }\n# is_stateful: true\n# }\na, b = 2\n\n'
filename = '<unknown>', mode = 'exec'
def parse(source, filename='<unknown>', mode='exec', *,
type_comments=False, feature_version=None):
"""
Parse the source into an AST node.
Equivalent to compile(source, filename, mode, PyCF_ONLY_AST).
Pass type_comments=True to get back type comments where the syntax allows.
"""
flags = PyCF_ONLY_AST
if type_comments:
flags |= PyCF_TYPE_COMMENTS
if isinstance(feature_version, tuple):
major, minor = feature_version # Should be a 2-tuple.
assert major == 3
feature_version = minor
elif feature_version is None:
feature_version = -1
# Else it should be an int giving the minor version for 3.x.
> return compile(source, filename, mode, flags,
_feature_version=feature_version)
E File "<unknown>", line 6
E # type: DT_RESOURCE
E ^
E SyntaxError: invalid syntax
/usr/lib64/python3.9/ast.py:50: SyntaxError
The above exception was the direct cause of the following exception:
@pytest.mark.xfail(
reason=(
"The builtin ast module does not fail with a specific error "
"for syntax error caused by invalid type comments."
),
)
def test_parse_module_with_invalid_type_comments_does_not_crash():
> node = builder.parse(
"""
# op {
# name: "AssignAddVariableOp"
# input_arg {
# name: "resource"
# type: DT_RESOURCE
# }
# input_arg {
# name: "value"
# type_attr: "dtype"
# }
# attr {
# name: "dtype"
# type: "type"
# }
# is_stateful: true
# }
a, b = 2
"""
)
tests/test_builder.py:931:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
astroid/builder.py:303: in parse
return builder.string_build(code, modname=module_name, path=path)
astroid/builder.py:151: in string_build
module, builder = self._data_build(data, modname, path)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <astroid.builder.AstroidBuilder object at 0x7f7a9c545310>
data = '\n# op {\n# name: "AssignAddVariableOp"\n# input_arg {\n# name: "resource"\n# type: DT_RESOURCE\n# }\n#...tr: "dtype"\n# }\n# attr {\n# name: "dtype"\n# type: "type"\n# }\n# is_stateful: true\n# }\na, b = 2\n'
modname = '', path = None
def _data_build(
self, data: str, modname: str, path: str | None
) -> tuple[nodes.Module, rebuilder.TreeRebuilder]:
"""Build tree node from data and add some informations."""
try:
node, parser_module = _parse_string(
data, type_comments=True, modname=modname
)
except (TypeError, ValueError, SyntaxError) as exc:
> raise AstroidSyntaxError(
"Parsing Python code failed:\n{error}",
source=data,
modname=modname,
path=path,
error=exc,
) from exc
E astroid.exceptions.AstroidSyntaxError: Parsing Python code failed:
E invalid syntax (<unknown>, line 6)
astroid/builder.py:185: AstroidSyntaxError
________________________________________________________________________ InferenceTest.test_descriptor_are_callable _________________________________________________________________________
self = <tests.test_inference.InferenceTest testMethod=test_descriptor_are_callable>
@pytest.mark.xfail(reason="Descriptors are not properly inferred as callable")
def test_descriptor_are_callable(self):
code = """
class A:
statm = staticmethod(open)
clsm = classmethod('whatever')
"""
ast = parse(code, __name__)
statm = next(ast["A"].igetattr("statm"))
> self.assertTrue(statm.callable())
E AssertionError: Uninferable is not true
tests/test_inference.py:539: AssertionError
________________________________________________________________ InferenceTest.test_factory_methods_inside_binary_operation _________________________________________________________________
self = <tests.test_inference.InferenceTest testMethod=test_factory_methods_inside_binary_operation>
@pytest.mark.xfail(
reason="pathlib.Path cannot be inferred on Python 3.8",
)
def test_factory_methods_inside_binary_operation(self):
node = extract_node(
"""
from pathlib import Path
h = Path("/home")
u = h / "user"
u #@
"""
)
> assert next(node.infer()).qname() == "pathlib.Path"
E AssertionError: assert Uninferable == 'pathlib.Path'
E + where Uninferable = Uninferable()
E + where Uninferable = Uninferable.qname
E + where Uninferable = next(<generator object NodeNG.infer at 0x7f7a9c0fcc80>)
E + where <generator object NodeNG.infer at 0x7f7a9c0fcc80> = <bound method NodeNG.infer of <Name.u l.5 at 0x7f7a9b8d0fa0>>()
E + where <bound method NodeNG.infer of <Name.u l.5 at 0x7f7a9b8d0fa0>> = <Name.u l.5 at 0x7f7a9b8d0fa0>.infer
tests/test_inference.py:988: AssertionError
__________________________________________________________________________ InferenceTest.test_function_metaclasses __________________________________________________________________________
self = <tests.test_inference.InferenceTest testMethod=test_function_metaclasses>
@pytest.mark.xfail(reason="Does not support function metaclasses")
def test_function_metaclasses(self):
# These are not supported right now, although
# they will be in the future.
ast_node = extract_node(
"""
class BookMeta(type):
author = 'Rushdie'
def metaclass_function(*args):
return BookMeta
class Book(object, metaclass=metaclass_function):
pass
Book #@
"""
)
inferred = next(ast_node.infer())
metaclass = inferred.metaclass()
> self.assertIsInstance(metaclass, nodes.ClassDef)
E AssertionError: <FunctionDef.metaclass_function l.5 at 0x7f7a9bf7c820> is not an instance of <class 'astroid.nodes.scoped_nodes.scoped_nodes.ClassDef'>
tests/test_inference.py:4033: AssertionError
_____________________________________________________________ InferenceTest.test_metaclass_arguments_are_classes_not_instances ______________________________________________________________
self = <tests.test_inference.InferenceTest testMethod=test_metaclass_arguments_are_classes_not_instances>
@pytest.mark.xfail(reason="Metaclass arguments not inferred as classes")
def test_metaclass_arguments_are_classes_not_instances(self):
ast_node = extract_node(
"""
class A(type):
def test(cls): return cls
A.test() #@
"""
)
# This is not supported yet
inferred = next(ast_node.infer())
> self.assertIsInstance(inferred, nodes.ClassDef)
E AssertionError: <Instance of .A at 0x140164614188720> is not an instance of <class 'astroid.nodes.scoped_nodes.scoped_nodes.ClassDef'>
tests/test_inference.py:4210: AssertionError
__________________________________________________________________ TestInferencePropagation.test_call_context_propagation ___________________________________________________________________
self = <tests.test_inference.TestInferencePropagation object at 0x7f7aa2e42c70>
@pytest.mark.xfail(reason="Relying on path copy")
def test_call_context_propagation(self):
n = extract_node(
"""
def chest(a):
return a * a
def best(a, b):
return chest(a)
def test(a, b, c):
return best(a, b)
test(4, 5, 6) #@
"""
)
> assert next(n.infer()).as_string() == "16"
E AssertionError: assert Uninferable == '16'
E + where Uninferable = Uninferable()
E + where Uninferable = Uninferable.as_string
E + where Uninferable = next(<generator object NodeNG.infer at 0x7f7a9f1d5d60>)
E + where <generator object NodeNG.infer at 0x7f7a9f1d5d60> = <bound method NodeNG.infer of <Call l.8 at 0x7f7aa2ec7430>>()
E + where <bound method NodeNG.infer of <Call l.8 at 0x7f7aa2ec7430>> = <Call l.8 at 0x7f7aa2ec7430>.infer
tests/test_inference.py:5703: AssertionError
______________________________________________________________________________ test_compare_identity[is-True] _______________________________________________________________________________
op = 'is', result = True
@pytest.mark.xfail(reason="uninferable")
@pytest.mark.parametrize(
"op,result",
[
("is", True),
("is not", False),
],
)
def test_compare_identity(op, result) -> None:
code = f"""
obj = object()
obj {op} obj
"""
node = extract_node(code)
inferred = next(node.infer())
> assert inferred.value == result
E assert Uninferable == True
E + where Uninferable = Uninferable.value
tests/test_inference.py:5761: AssertionError
____________________________________________________________________________ test_compare_identity[is not-False] ____________________________________________________________________________
op = 'is not', result = False
@pytest.mark.xfail(reason="uninferable")
@pytest.mark.parametrize(
"op,result",
[
("is", True),
("is not", False),
],
)
def test_compare_identity(op, result) -> None:
code = f"""
obj = object()
obj {op} obj
"""
node = extract_node(code)
inferred = next(node.infer())
> assert inferred.value == result
E assert Uninferable == False
E + where Uninferable = Uninferable.value
tests/test_inference.py:5761: AssertionError
___________________________________________________________________________________ test_compare_dynamic ____________________________________________________________________________________
@pytest.mark.xfail(reason="unimplemented")
def test_compare_dynamic() -> None:
code = """
class A:
def __le__(self, other):
return True
A() <= None
"""
node = extract_node(code)
inferred = next(node.infer())
> assert inferred.value is True
E assert Uninferable is True
E + where Uninferable = Uninferable.value
tests/test_inference.py:5855: AssertionError
______________________________________________________________________________ test_compare_known_false_branch ______________________________________________________________________________
@pytest.mark.xfail(reason="unimplemented")
def test_compare_known_false_branch() -> None:
code = """
a = 'hello'
if 1 < 2:
a = 'goodbye'
a
"""
node = extract_node(code)
inferred = list(node.infer())
> assert len(inferred) == 1
E assert 2 == 1
E + where 2 = len([<Const.str l.2 at 0x7f7a9c4eea90>, <Const.str l.4 at 0x7f7a9c4ee7c0>])
tests/test_inference.py:5898: AssertionError
_______________________________________________________________________ test_recursion_error_self_reference_type_call _______________________________________________________________________
@pytest.mark.xfail(reason="Cannot fully infer all the base classes properly.")
def test_recursion_error_self_reference_type_call() -> None:
# Fix for https://github.com/pylint-dev/astroid/issues/199
code = """
class A(object):
pass
class SomeClass(object):
route_class = A
def __init__(self):
self.route_class = type('B', (self.route_class, ), {})
self.route_class() #@
"""
node = extract_node(code)
inferred = next(node.infer())
assert isinstance(inferred, Instance)
assert inferred.name == "B"
# TODO: Cannot infer [B, A, object] but at least the recursion error is gone.
> assert [cls.name for cls in inferred.mro()] == ["B", "A", "object"]
E AssertionError: assert ['B', 'object'] == ['B', 'A', 'object']
E
E At index 1 diff: 'object' != 'A'
E Right contains one more item: 'object'
E Use -v to get more diff
tests/test_inference.py:6873: AssertionError
__________________________________________________________ InstanceModelTest.test_instance_local_attributes_overrides_object_model __________________________________________________________
self = <tests.test_object_model.InstanceModelTest testMethod=test_instance_local_attributes_overrides_object_model>
@pytest.mark.xfail(reason="Instance lookup cannot override object model")
def test_instance_local_attributes_overrides_object_model(self):
# The instance lookup needs to be changed in order for this to work.
ast_node = builder.extract_node(
"""
class A:
@property
def __dict__(self):
return []
A().__dict__
"""
)
inferred = next(ast_node.infer())
> self.assertIsInstance(inferred, astroid.List)
E AssertionError: <Dict.dict l.2 at 0x7f7a9d2be400> is not an instance of <class 'astroid.nodes.node_classes.List'>
tests/test_object_model.py:71: AssertionError
___________________________________________________________________ FunctionModelTest.test_descriptor_not_inferrring_self ___________________________________________________________________
self = <tests.test_object_model.FunctionModelTest testMethod=test_descriptor_not_inferrring_self>
@pytest.mark.xfail(reason="Descriptors cannot infer what self is")
def test_descriptor_not_inferrring_self(self):
# We can't infer __get__(X, Y)() when the bounded function
# uses self, because of the tree's parent not being propagating good enough.
result = builder.extract_node(
"""
class A(object):
x = 42
def test(self): return self.x
f = test.__get__(A(), A)
f() #@
"""
)
result = next(result.infer())
> self.assertIsInstance(result, astroid.Const)
E AssertionError: Uninferable is not an instance of <class 'astroid.nodes.node_classes.Const'>
tests/test_object_model.py:390: AssertionError
================================================================================== short test summary info ==================================================================================
SKIPPED [1] tests/test_type_params.py:19: Requires Python 3.12 or higher
SKIPPED [1] tests/brain/numpy/test_core_einsumfunc.py:30: This test requires the numpy library.
SKIPPED [1] tests/brain/numpy/test_core_einsumfunc.py:44: This test requires the numpy library.
SKIPPED [1] tests/brain/numpy/test_core_fromnumeric.py:33: This test requires the numpy library.
SKIPPED [1] tests/brain/numpy/test_core_function_base.py:37: This test requires the numpy library.
SKIPPED [1] tests/brain/numpy/test_core_multiarray.py:104: This test requires the numpy library.
SKIPPED [1] tests/brain/numpy/test_core_multiarray.py:126: This test requires the numpy library.
SKIPPED [1] tests/brain/numpy/test_core_multiarray.py:82: This test requires the numpy library.
SKIPPED [1] tests/brain/numpy/test_core_multiarray.py:148: This test requires the numpy library.
SKIPPED [1] tests/brain/numpy/test_core_multiarray.py:170: This test requires the numpy library.
SKIPPED [1] tests/brain/numpy/test_core_numeric.py:42: This test requires the numpy library.
SKIPPED [4] tests/brain/numpy/test_core_numeric.py:60: This test requires the numpy library.
SKIPPED [1] tests/brain/numpy/test_core_numerictypes.py:296: This test requires the numpy library.
SKIPPED [1] tests/brain/numpy/test_core_numerictypes.py:307: This test requires the numpy library.
SKIPPED [1] tests/brain/numpy/test_core_numerictypes.py:335: This test requires the numpy library.
SKIPPED [1] tests/brain/numpy/test_core_numerictypes.py:209: This test requires the numpy library.
SKIPPED [1] tests/brain/numpy/test_core_numerictypes.py:97: This test requires the numpy library.
SKIPPED [1] tests/brain/numpy/test_core_numerictypes.py:267: This test requires the numpy library.
SKIPPED [1] tests/brain/numpy/test_core_numerictypes.py:90: This test requires the numpy library.
SKIPPED [1] tests/brain/numpy/test_core_umath.py:112: This test requires the numpy library.
SKIPPED [1] tests/brain/numpy/test_core_umath.py:119: This test requires the numpy library.
SKIPPED [1] tests/brain/numpy/test_core_umath.py:127: This test requires the numpy library.
SKIPPED [1] tests/brain/numpy/test_core_umath.py:173: This test requires the numpy library.
SKIPPED [1] tests/brain/numpy/test_core_umath.py:134: This test requires the numpy library.
SKIPPED [1] tests/brain/numpy/test_core_umath.py:195: This test requires the numpy library.
SKIPPED [1] tests/brain/numpy/test_core_umath.py:214: This test requires the numpy library.
SKIPPED [1] tests/brain/numpy/test_core_umath.py:153: This test requires the numpy library.
SKIPPED [4] tests/brain/numpy/test_ma.py:26: This test requires the numpy library.
SKIPPED [1] tests/brain/numpy/test_ndarray.py:127: This test requires the numpy library.
SKIPPED [1] tests/brain/numpy/test_ndarray.py:142: This test requires the numpy library.
SKIPPED [1] tests/brain/numpy/test_ndarray.py:157: This test requires the numpy library.
SKIPPED [1] tests/brain/numpy/test_random_mtrand.py:85: This test requires the numpy library.
SKIPPED [1] tests/brain/numpy/test_random_mtrand.py:92: This test requires the numpy library.
SKIPPED [1] astroid/test_utils.py:45: Needs Python <= 3.8. Current version is 3.9.18.final.0.
SKIPPED [1] tests/brain/test_brain.py:116: Needs Python 3 io model / doesn't work with plain pytest.use pytest -s for this test to work
SKIPPED [3] astroid/test_utils.py:45: Needs Python <= 3.9. Current version is 3.9.18.final.0.
SKIPPED [1] astroid/test_utils.py:43: Needs Python > 3.10. Current version is 3.9.18.final.0.
SKIPPED [1] tests/brain/test_nose.py:24: This test requires nose library.
SKIPPED [1] tests/brain/test_qt.py:24: These tests require the PyQt6 library.
SKIPPED [1] tests/brain/test_qt.py:44: These tests require the PyQt6 library.
SKIPPED [1] tests/brain/test_qt.py:59: These tests require the PyQt6 library.
SKIPPED [1] tests/brain/test_regex.py:19: This test requires the regex library.
SKIPPED [1] tests/brain/test_regex.py:27: This test requires the regex library.
SKIPPED [1] tests/brain/test_six.py:24: These tests require the six library
SKIPPED [1] tests/brain/test_six.py:67: These tests require the six library
SKIPPED [1] tests/brain/test_six.py:79: These tests require the six library
SKIPPED [1] tests/brain/test_six.py:120: These tests require the six library
SKIPPED [1] tests/brain/test_six.py:135: These tests require the six library
SKIPPED [1] tests/brain/test_six.py:93: These tests require the six library
SKIPPED [1] tests/test_group_exceptions.py:23: Requires Python 3.11 or higher
SKIPPED [1] tests/test_group_exceptions.py:54: Requires Python 3.11 or higher
SKIPPED [1] tests/test_group_exceptions.py:96: Requires Python 3.11 or higher
SKIPPED [1] tests/test_inference.py:3282: These tests require the six library
SKIPPED [1] tests/test_inference.py:3638: These tests require the six library
SKIPPED [1] tests/test_inference.py:3248: These tests require the six library
SKIPPED [1] tests/test_inference.py:4146: These tests require the six library
SKIPPED [1] tests/test_inference.py:4164: These tests require the six library
SKIPPED [1] tests/test_inference.py:6733: Exact inference with dataclasses (replace function) in python3.9
SKIPPED [1] tests/test_modutils.py:454: Backport valid on <=3.9
SKIPPED [1] tests/test_nodes.py:318: Uses 3.12 type param nodes
SKIPPED [1] tests/test_nodes.py:300: Uses 3.12 type param nodes
SKIPPED [1] tests/test_nodes.py:306: Uses 3.12 type param nodes
SKIPPED [1] tests/test_nodes.py:312: Uses 3.12 type param nodes
SKIPPED [1] tests/test_nodes.py:1707: pattern matching was added in PY310
SKIPPED [1] tests/test_nodes.py:1762: pattern matching was added in PY310
SKIPPED [1] tests/test_nodes.py:1816: pattern matching was added in PY310
SKIPPED [1] tests/test_nodes.py:1866: pattern matching was added in PY310
SKIPPED [1] tests/test_nodes.py:1942: pattern matching was added in PY310
SKIPPED [1] tests/test_nodes_lineno.py:23: end_lineno and end_col_offset were added in PY38
SKIPPED [1] tests/test_nodes_lineno.py:1045: pattern matching was added in PY310
SKIPPED [1] tests/test_protocols.py:347: Match requires python 3.10
SKIPPED [1] tests/test_protocols.py:366: Match requires python 3.10
SKIPPED [1] tests/test_protocols.py:386: Match requires python 3.10
SKIPPED [1] tests/test_protocols.py:422: Generic typing syntax requires python 3.12
SKIPPED [1] tests/test_protocols.py:430: Generic typing syntax requires python 3.12
SKIPPED [1] tests/test_protocols.py:438: Generic typing syntax requires python 3.12
SKIPPED [1] tests/test_regrtest.py:86: Needs numpy
SKIPPED [1] tests/test_regrtest.py:102: Needs numpy
SKIPPED [1] tests/test_scoped_nodes.py:1441: These tests require the six library
SKIPPED [1] tests/test_scoped_nodes.py:1455: These tests require the six library
SKIPPED [1] tests/test_scoped_nodes.py:1484: These tests require the six library
SKIPPED [1] tests/test_scoped_nodes.py:1656: These tests require the six library
XFAIL tests/brain/test_brain.py::TestLenBuiltinInference::test_int_subclass_argument - Can't use list special astroid fields
XFAIL tests/brain/test_ctypes.py::test_ctypes_redefined_types_members[c_buffer-bytes-<class 'ctypes.c_char'>] - c_buffer is Uninferable but for now we do not know why
XFAIL tests/brain/test_dataclasses.py::test_dataclass_non_default_argument_after_default - Transforms returning Uninferable isn't supported.
XFAIL tests/test_builder.py::test_parse_module_with_invalid_type_comments_does_not_crash - The builtin ast module does not fail with a specific error for syntax error caused by invalid type comments.
XFAIL tests/test_inference.py::InferenceTest::test_descriptor_are_callable - Descriptors are not properly inferred as callable
XFAIL tests/test_inference.py::InferenceTest::test_factory_methods_inside_binary_operation - pathlib.Path cannot be inferred on Python 3.8
XFAIL tests/test_inference.py::InferenceTest::test_function_metaclasses - Does not support function metaclasses
XFAIL tests/test_inference.py::InferenceTest::test_metaclass_arguments_are_classes_not_instances - Metaclass arguments not inferred as classes
XFAIL tests/test_inference.py::TestInferencePropagation::test_call_context_propagation - Relying on path copy
XFAIL tests/test_inference.py::test_compare_identity[is-True] - uninferable
XFAIL tests/test_inference.py::test_compare_identity[is not-False] - uninferable
XFAIL tests/test_inference.py::test_compare_dynamic - unimplemented
XFAIL tests/test_inference.py::test_compare_known_false_branch - unimplemented
XFAIL tests/test_inference.py::test_recursion_error_self_reference_type_call - Cannot fully infer all the base classes properly.
XFAIL tests/test_object_model.py::InstanceModelTest::test_instance_local_attributes_overrides_object_model - Instance lookup cannot override object model
XFAIL tests/test_object_model.py::FunctionModelTest::test_descriptor_not_inferrring_self - Descriptors cannot infer what self is
FAILED tests/test_manager.py::IsolatedAstroidManagerTest::test_no_user_warning - astroid.exceptions.AstroidImportError: Failed to import module pip with error:
================================================================== 1 failed, 1573 passed, 90 skipped, 16 xfailed in 22.75s ==================================================================
List of installed modules in build env:
Package Version
----------------------------- -----------
alabaster 0.7.16
Babel 2.14.0
build 1.1.1
charset-normalizer 3.3.2
distro 1.9.0
dnf 4.19.0
docutils 0.20.1
exceptiongroup 1.1.3
gpg 1.23.2
idna 3.6
imagesize 1.4.1
importlib_metadata 7.0.1
iniconfig 2.0.0
installer 0.7.0
Jinja2 3.1.3
lazy-object-proxy 1.10.0
libdnf 0.73.0
MarkupSafe 2.1.3
packaging 24.0
pluggy 1.4.0
Pygments 2.17.2
pyproject_hooks 1.0.0
pytest 8.1.1
python-dateutil 2.9.0.post0
requests 2.31.0
setuptools 69.1.1
snowballstemmer 2.2.0
Sphinx 7.2.6
sphinxcontrib-applehelp 1.0.8
sphinxcontrib-devhelp 1.0.5
sphinxcontrib-htmlhelp 2.0.5
sphinxcontrib-jsmath 1.0.1
sphinxcontrib-qthelp 1.0.7
sphinxcontrib-serializinghtml 1.1.10
tokenize_rt 5.2.0
tomli 2.0.1
typing_extensions 4.10.0
urllib3 1.26.18
wheel 0.43.0
wrapt 1.16.0
zipp 3.17.0
Please let me know if you need more details or want me to perform some diagnostics.
Thanks for the report. I guess we could just skip this test if pip is not available.