Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Infinite loop at the end of file makes pytype output name-error with global lambda referring to a global variable #1842

Open
Jik opened this issue Nov 20, 2024 · 0 comments

Comments

@Jik
Copy link

Jik commented Nov 20, 2024

Consider the following file

b = 1
lam = lambda: b

This passes pytype without problems.

However, adding an extra while loop at the end:

b = 1
lam = lambda: b

while True:
    pass

I now get an error:

jik@hostname:~/projects/test$ pytype --version
2024.10.11
jik@hostname:~/projects/test$ pytype simple.py
Computing dependencies
Analyzing 1 sources with 0 local dependencies
ninja: Entering directory `.pytype'
[1/1] check simple
FAILED: /home/jik/projects/test/.pytype/pyi/simple.pyi
/usr/bin/python3 -m pytype.main --imports_info /home/jik/projects/test/.pytype/imports/simple.imports --module-name simple --platform linux -V 3.10 -o /home/jik/projects/test/.pytype/pyi/simple.pyi --analyze-annotated --nofail --quick /home/jik/projects/test/simple.py
/home/jik/projects/test/simple.py:2:1: error: in <lambda>: Name 'b' is not defined [name-error]

lam = lambda: b~~~~~~~~~~~~~~
lam = lambda: b



For more details, see https://google.github.io/pytype/errors.html#name-error
ninja: build stopped: subcommand failed.
Leaving directory '.pytype'

It passes again if I replace the pass by break or if I change the while True to while False/if True/if False, so I guess there's something particular with the infinite loop that confuses pytype.

@Jik Jik changed the title Infinite loop at the end of file confuses pytype with global lambda referring to a global variable Infinite loop at the end of file makes pytype output name-error with global lambda referring to a global variable Nov 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant