Use an explicit mapping for locals in this test

In Python 3.13 the `locals` function now returns a fresh mapping
each time it's called (when called in a function). We thus need
to store a reference to the mapping being used, rather than
re-fetching it each time.

Since we don't actually need to modify the locals within the scope
of the test function itself, it suffices to use our own mapping
here rather than the result of calling `locals`, which fully
isolates this test from the nature of that function.

Fixes https://github.com/davidhalter/jedi/issues/2002
This commit is contained in:
Peter Law
2024-06-23 13:01:58 +01:00
parent 473b35e6ec
commit 340dedd021

View File

@@ -310,8 +310,9 @@ def test_completion_param_annotations():
# Need to define this function not directly in Python. Otherwise Jedi is too
# clever and uses the Python code instead of the signature object.
code = 'def foo(a: 1, b: str, c: int = 1.0) -> bytes: pass'
exec(code, locals())
script = jedi.Interpreter('foo', [locals()])
exec_locals = {}
exec(code, exec_locals)
script = jedi.Interpreter('foo', [exec_locals])
c, = script.complete()
sig, = c.get_signatures()
a, b, c = sig.params
@@ -323,7 +324,7 @@ def test_completion_param_annotations():
assert b.description == 'param b: str'
assert c.description == 'param c: int=1.0'
d, = jedi.Interpreter('foo()', [locals()]).infer()
d, = jedi.Interpreter('foo()', [exec_locals]).infer()
assert d.name == 'bytes'