Skip to content

Commit

Permalink
Use an explicit mapping for locals in this test
Browse files Browse the repository at this point in the history
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 davidhalter#2002
  • Loading branch information
PeterJCLaw committed Jun 23, 2024
1 parent 6d37b46 commit 2892291
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions test/test_api/test_interpreter.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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'


Expand Down

0 comments on commit 2892291

Please sign in to comment.