Hacktoberfest 2026: the issues maintainers tagged for October, open and beginner-friendly. Browse Hacktoberfest issues

Cannot use field twice after an `is not None` check?

Open
#145 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
35/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Stale
Tech stack
python
Domain
compilers

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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from facebookincubator/MetaPython

All issues in facebookincubator/MetaPython

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.