`and` fails to refine `Optional[T]`
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 45/100
Research direction
Start with the reproducer in optional_refine_and.py and compare its behavior with the failing dual case in optional_refine_or.py. Run the static compiler against the examples to inspect the reported type refinement. Done means the and program is accepted while the or program continues to reject passing None to expect_int.
Written by the indexing model from the issue text.
Description
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]#
- Dominant language
- Python
- Stars
- 3.8k
- Forks
- 139
- PR merge metrics
- No merged PRs in 30d
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from facebookincubator/MetaPython
-
Difficulty 4/5 3-5 days Newbie friendliness 35/100
facebookincubator/MetaPython#147 ·
-
Difficulty 4/5 3-5 days Newbie friendliness 45/100
facebookincubator/MetaPython#146 · 2 comments ·
-
Difficulty 4/5 3-5 days Newbie friendliness 35/100
facebookincubator/MetaPython#145 · 4 comments ·
-
Difficulty 3/5 1-2 days Newbie friendliness 30/100
facebookincubator/MetaPython#144 · 1 comment ·
-
Difficulty 4/5 3-5 days Newbie friendliness 20/100
facebookincubator/MetaPython#129 · 2 comments ·
All issues in facebookincubator/MetaPython
Similar issues
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 90/100
learningequality/ricecooker#747 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
BSData/horus-heresy-3rd-edition#3171 ·
-
enhancement
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
run-llama/llama_index#23199 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
KhronosGroup/glTF-Blender-IO#2769 ·