inspect now raises OSError for objects without source file

CPython issue: https://bugs.python.org/issue44648
This commit is contained in:
Lumír 'Frenzy' Balhar
2021-08-05 08:24:35 +02:00
committed by Lumir Balhar
parent 1d944943c3
commit eab1b8be8b
2 changed files with 22 additions and 1 deletions

View File

@@ -711,3 +711,24 @@ def test_negate():
assert x.name == 'int'
value, = x._name.infer()
assert value.get_safe_value() == -3
def test_complete_not_findable_class_source():
class TestClass():
ta=1
ta1=2
# Simulate the environment where the class is defined in
# an interactive session and therefore inspect module
# cannot find its source code and raises OSError (Py 3.10+) or TypeError.
TestClass.__module__ = "__main__"
# There is a pytest __main__ module we have to remove temporarily.
module = sys.modules.pop("__main__")
try:
interpreter = jedi.Interpreter("TestClass.", [locals()])
completions = interpreter.complete(column=10, line=1)
finally:
sys.modules["__main__"] = module
assert "ta" in [c.name for c in completions]
assert "ta1" in [c.name for c in completions]