Skip to content

short circuit based on sys.version_info in bool op #3554

@MarcoGorelli

Description

@MarcoGorelli

Describe the Bug

import sys

if sys.version_info >= (3, 15):
    A = 3


def foo(a: object) -> None:

    if sys.version_info >= (3, 15):
        print(A)
    if sys.version_info >= (3, 15) and A:
        print(A)

pyrefly is ok with the print(A) after the first if statement, but not with the second if statement

(scratch) mgorelli@marcoslaptop:~/scratch$ mypy t.py
Success: no issues found in 1 source file
(scratch) mgorelli@marcoslaptop:~/scratch$ pyright t.py
0 errors, 0 warnings, 0 informations
(scratch) mgorelli@marcoslaptop:~/scratch$ ty check t.py
All checks passed!
(scratch) mgorelli@marcoslaptop:~/scratch$ zuban check t.py
Success: no issues found in 1 source file
(scratch) mgorelli@marcoslaptop:~/scratch$ pyrefly check t.py
ERROR Could not find name `A` [unknown-name]
  --> t.py:11:40
   |
11 |     if sys.version_info >= (3, 15) and A:
   |                                        ^
   |
 INFO 1 error

Sandbox Link

https://pyrefly.org/sandbox/?project=N4IgZglgNgpgziAXKOBDAdgEwEYHsAeAdAA4CeSIEAtsbgE4AuABHKXADrqcRgtuEA3GHTgRc6APoR0YXEwB8AXiYAKAMwAaJgEYArAEpEnJiaYBBJsrWcbWGL1m4VqRE1zYAVjADGDfUwBaeSYAOXEYIy50UyYePjhBYVFxKRk5JVVNHQNImJjiOmkGFTN9Y1M41gShETFJaVkFZXUtPX8MTHNcvJMCopL9EA0QMjp7KFJCBlwqKAoAYiYABVIxsAmWDrx8Jm9xSABzAFc6VAY6wk5FgGUYGCYACwYGYjhEAHp30fHJ%2BgP3mDod6YXDeODvPYyCDHU7ncTvJiyOhMVACVDQVDYWC7fbQk5nOpuYhw9AJThkBgPcQBGrJaLKdggNSEbQAJkZnAA2sI6PQ4ABdThHdDUWiMGCYAKYCBjXwQISWJgAcmh6HoMCVnDVDACYwAjkcZRKAgBrGCkAKobzeeBwRVKgDuqDo6E16BAAF9hlbzkIAGLQGAUNBYbYkcgeoA

(Only applicable for extension issues) IDE Information

No response

Metadata

Metadata

Assignees

No one assigned
    No fields configured for Feature.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions