Cannot use field twice after an `is not None` check?
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 35/100
Research direction
Start by running the supplied score1/score2 reproducer with Python 3.10.5 and Cinder commit 1aeff3259dc. Compare the type-checking behavior for repeated self.parent accesses; done means score2 produces no TypedSyntaxError, matching score1.
Written by the indexing model from the issue text.
Description
On Python 3.10.5+cinder, Cinder commit 1aeff3259dc
Example program:
class Node:
def __init__(self) -> None:
self.wins: int = 0
self.losses: int = 0
self.parent: None | Node = None
def score1(self) -> int:
n = 0
if self.parent is not None:
n += self.parent.wins
if self.parent is not None:
n += self.parent.losses
return n
def score2(self) -> int:
n = 0
if self.parent is not None:
n += self.parent.losses
n += self.parent.wins # type error !?
return n
Expected no type error.
But got a type error inside score2 accessing self.parent.wins:
File "foo.py", line 20
n += self.parent.wins
^
cinderx.compiler.errors.TypedSyntaxError: Optional[__main__.Node]: 'NoneType' object has no attribute 'wins'
If you swap that line and the previous one, the error is on self.parent.losses instead!
- 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 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 ·
-
Difficulty 4/5 3-5 days Newbie friendliness 35/100
facebookincubator/MetaPython#116 · 2 comments ·
All issues in facebookincubator/MetaPython
Similar issues
-
enhancement
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
canonical/paas-charm#368 · 1 comment ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
-
tech debt
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
-
Difficulty 1/5 Under an hour Newbie friendliness 90/100
StevenBlack/hosts#3256 ·
-
Difficulty 1/5 Under an hour Newbie friendliness 90/100
qualcomm/qai-appbuilder#275 ·