Skip to content

Attribute narrowing with optional value #897

Description

@maggiemoss

Describe the Bug

def question() -> bool:
    return True

class A:
    arg: int | None 

inst = A()
# abs is load bearing
inst.arg = abs(int(0))

if question():
    # see bytecode size comment in the absolute jump case above
    inst.arg += 2

Sandbox Link

https://pyrefly.org/sandbox/?code=CYUwZgBAjgriDOAXAlgewHYAoCUEC0AfBAEaqoA2AXAFAR0QBOIiMD6EAKg3NbwMbkAhvHgQAgjXoRBDAOaUIydIggAfCADkMICLyVIIAXnE5qAYmnFRyUeVSDgJEDKWzq%2BxADoZso5fiYSoiYAAzY2HqQsAgoGDiS9BbwIDrEAJ6IIHyooBDwyABeOtkAtiUgyorsiAAWOoJWFDCZEABWMCUADhB8wvWkAG4gtPQe3nIQANTGAExAA&version=3.12

(Only applicable for extension issues) IDE Information

No response

Metadata

Metadata

Labels

narrowingIssues with narrowing - root cause is usually narrowing, flow handling, or bothpytorch

Type

Fields

No fields configured for Bug.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions