Skip to content

"May be uninitialized" with two equivalent if branches #3227

@thomasaarholt

Description

@thomasaarholt

Describe the Bug

I got a colleague complaining about mypy allowing this but pyrefly complaining. Is supporting this behaviour within scope?

foo: bool = True
if foo:
    bar = 1

if foo:
    bar +=1 # `bar` may be uninitialized [[unbound-name](https://pyrefly.org/en/docs/error-kinds/#unbound-name)]

Sandbox Link

https://pyrefly.org/sandbox/?project=N4IgZglgNgpgziAXKOBDAdgEwEYHsAeAdAA4CeS4uuiABHrlDQLw0AqATgK4wA66EYGmCqI%2BNcXVTtmNAIx8%2BAoSLETsUmgGom89CAA0IMuxhgopQgBdcAWygUAxDQAKpE2dI00WPPhoBjXHRIAHNOdlRLCCDCPicAZRgYGgALS0tiOEQAemzjU3NCXHYQ7Jh0bMxcfzhswOCIMIiooOzlaVQAN1RoVGxYAKDQ8Mjo9BpcYhb0OFj0MksUoIBaTph2ODGZHhAAZkJZACYdvgBtdfZiuABdPk5%2BG2JiyxhMZcwIE38otZkAcka6GKMD%2BfCBlmWJgAjpxPq9lgBrGCkZaofz%2BeBwf4Adyk6FBegAvoY0T8YAAxaAwCjeHAEEjkQlAA

(Only applicable for extension issues) IDE Information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions