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

and fails to refine Optional[T] #63

Open
LuKuangChen opened this issue Dec 29, 2021 · 0 comments
Open

and fails to refine Optional[T] #63

LuKuangChen opened this issue Dec 29, 2021 · 0 comments
Labels
sp-correctness static python correctness staticpython static python issues

Comments

@LuKuangChen
Copy link

a4a71ae
2021-12-29

What program did you run?

# optional_refine_and.py
# This should pass.
# This should terminate.

from typing import Optional

def expect_int(i: int) -> None:
    return

def f(x: Optional[int]) -> None:
    return x and expect_int(x)

assert f(None) is None
assert f(42) is None

What happened?

    return x and expect_int(x)
    ^
compiler.errors.TypedSyntaxError: return type must be None, not Optional[int]

What should have happened?

The program should be accepted by the type checker.

Note that a dual test fails as expected.

[root@0fcdc5077884 vol]# cat Playground/conformance_suite/optional_refine_or.py 
# optional_refine_or.py
# This should fail.

from typing import Optional

def expect_int(i: int) -> int:
    return 42

def f(x: Optional[int]) -> int:
    return x or expect_int(x)
[root@0fcdc5077884 vol]# ./python -m compiler --static Playground/conformance_suite/optional_refine_or.py 
Traceback (most recent call last):
  ....
  File "Playground/conformance_suite/optional_refine_or.py", line 10
    return x or expect_int(x)
                          ^
compiler.errors.TypedSyntaxError: type mismatch: None received for positional arg 'i', expected int
[root@0fcdc5077884 vol]# 
@carljm carljm added sp-correctness static python correctness staticpython static python issues labels Jan 11, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
sp-correctness static python correctness staticpython static python issues
Projects
None yet
Development

No branches or pull requests

2 participants