Closed Nowa-Ammerlaan closed 1 year ago
I'm testing jedi with Python 3.11 beta 5 on Fedora 36 and I see these failures:
================================================================================== short test summary info ===================================================================================
FAILED test/test_utils.py::TestSetupReadline::test_import - AssertionError: assert 37 < 30
FAILED test/test_api/test_classes.py::test_import - AssertionError: assert 'posixpath' in {'path'}
FAILED test/test_api/test_interpreter.py::test_string_annotation[annotations10-result10-] - AssertionError: assert ['str'] == []
FAILED test/test_api/test_interpreter.py::test_string_annotation[annotations13-result13-] - AssertionError: assert ['_AnyMeta'] == []
FAILED test/test_api/test_project.py::test_search[implicit_namespace_package.ns1.pkg-full_names20-kwargs20] - AssertionError: assert ['examples.im...kage.ns1.pkg'] == ['examples.im...kage...
FAILED test/test_api/test_project.py::test_search[implicit_namespace_package.-full_names24-kwargs24] - AssertionError: assert ['examples.im..._package.ns2'] == ['examples.im..._package.ns2']
FAILED test/test_inference/test_imports.py::test_find_module_not_package - AttributeError: 'NoneType' object has no attribute 'path'
FAILED test/test_inference/test_sys_path.py::test_venv_and_pths - AssertionError: assert ['/tmp/pytest...py:from_func'] == ['/tmp/pytest...py:from_func']
FAILED test/test_inference/test_gradual/test_stubs.py::test_infer_and_goto[import os; os.walk-os.walk-True-True-options0-kwargs0-direct-goto] - assert True == False
FAILED test/test_inference/test_gradual/test_stubs.py::test_infer_and_goto[import os; os.walk-os.walk-True-True-options0-kwargs0-direct-infer] - assert True == False
FAILED test/test_inference/test_gradual/test_stubs.py::test_infer_and_goto[import os; os.walk-os.walk-True-True-options0-kwargs0-indirect-goto] - assert True == False
FAILED test/test_inference/test_gradual/test_stubs.py::test_infer_and_goto[import os; os.walk-os.walk-True-True-options0-kwargs0-indirect-infer] - assert True == False
FAILED test/test_inference/test_gradual/test_typeshed.py::test_goto_stubs - AssertionError: assert True is False
FAILED test/test_inference/test_gradual/test_typeshed.py::test_goto_stubs_on_itself[import os; os.walk-goto] - AssertionError: assert PosixPath('/home/lbalhar/Software/jedi/jedi/third_par...
FAILED test/test_inference/test_gradual/test_typeshed.py::test_goto_stubs_on_itself[import os; os.walk-infer] - AssertionError: assert PosixPath('/home/lbalhar/Software/jedi/jedi/third_pa...
======================================================= 15 failed, 3770 passed, 56 skipped, 5 xfailed, 9 warnings in 155.16s (0:02:35) =======================================================
I'm not sure whether it's related to the problem or not but it seems that a lot of failed tests use os
and os.walk
as an example code. But I don't see any significant changes in Python related to the os
module.
I've been digging into some of these tests to find what is going on:
test/test_api/test_classes.py::test_import
I'm pretty sure just fails because of a change in the description
, so we can probably just adapt the test to look for path
instead of posixpath
:
i.e. on python3.10:
[<Name full_name='os.path', description='module posixpath'>, <Name full_name='os.path', description='module ntpath'>]
but on python3.11
[<Name full_name='os.path', description='module path'>]
I'm pretty sure the failure in test/test_inference/test_imports.py::test_find_module_not_package
is related to python3.11's "frozen imports":
i.e. on python3.10:
>>> import sys
>>> finders = sys.meta_path
>>> print(finders)
[<_distutils_hack.DistutilsMetaFinder object at 0x7fd0ccf21f90>, <class '_frozen_importlib.BuiltinImporter'>, <class '_frozen_importlib.FrozenImporter'>, <class '_frozen_importlib_external.PathFinder'>]
>>> finders[2].find_spec('io', None)
>>> finders[3].find_spec('io', None)
ModuleSpec(name='io', loader=<_frozen_importlib_external.SourceFileLoader object at 0x7fd0ccda3610>, origin='/usr/lib/python3.11/io.py')
but on python3.11
>>> import sys
>>> finders = sys.meta_path
>>> print(finders)
[<_distutils_hack.DistutilsMetaFinder object at 0x7fd0ccf21f90>, <class '_frozen_importlib.BuiltinImporter'>, <class '_frozen_importlib.FrozenImporter'>, <class '_frozen_importlib_external.PathFinder'>]
>>> finders[2].find_spec('io', None)
ModuleSpec(name='io', loader=<class '_frozen_importlib.FrozenImporter'>, origin='frozen')
>>> finders[3].find_spec('io', None)
ModuleSpec(name='io', loader=<_frozen_importlib_external.SourceFileLoader object at 0x7fd0ccda3610>, origin='/usr/lib/python3.11/io.py')
Since on pyhton3.11 _frozen_importlib.FrozenImporter
already returns something this is propagated further, but the lack of a path causes the test to fail further on.
I'm pretty sure the root cause for the failing *stubs*
tests is similar to the above. In test/test_inference/test_gradual/test_typeshed.py::test_goto_stubs
we import the os module which on python3.10 gives us <ModuleName: string_name=os start_pos=(1, 0)>
but on python3.11 <StubModuleName: string_name=os start_pos=(1, 0)>
which causes the is_stub()
function to return True instead of False.
The remaining two tests test/test_api/test_interpreter.py::test_string_annotation
fail because of:
python3.10:
>>> type(typing.Any)
<class 'typing._SpecialForm'>
>>> typing.Union["str", 1]
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python3.10/typing.py", line 312, in inner
return func(*args, **kwds)
File "/usr/lib/python3.10/typing.py", line 403, in __getitem__
return self._getitem(self, parameters)
File "/usr/lib/python3.10/typing.py", line 515, in Union
parameters = tuple(_type_check(p, msg) for p in parameters)
File "/usr/lib/python3.10/typing.py", line 515, in <genexpr>
parameters = tuple(_type_check(p, msg) for p in parameters)
File "/usr/lib/python3.10/typing.py", line 176, in _type_check
raise TypeError(f"{msg} Got {arg!r:.100}.")
TypeError: Union[arg, ...]: each arg must be a type. Got 1.
but with python3.11:
>>> type(typing.Any)
<class 'typing._AnyMeta'>
>>> typing.Union["str", 1]
typing.Union[ForwardRef('str'), 1]
The root cause is probably related to these changes, though I'm not sure how to fix it yet.
Testing with python 3.11, I am getting some test failures: