Skip to content

if x is None: x = <unnanotated call> doesn't clear None #4885

Description

@MarcoGorelli

Describe the Bug

def untyped_fallback(x):  # deliberately unannotated
    return x


def f(x: str | None) -> str:
    if x is None:
        y = untyped_fallback("default")
        print(y.upper())
        x = y
        print(x.upper())
    return x.upper()
ERROR sandbox.py:10:15-22: Object of class `NoneType` has no attribute `upper` [[missing-attribute](https://pyrefly.org/en/docs/error-kinds/#missing-attribute)]
ERROR sandbox.py:11:12-19: Object of class `NoneType` has no attribute `upper` [[missing-attribute](https://pyrefly.org/en/docs/error-kinds/#missing-attribute)]

Here, y is Unknown, as untyped_fallback. So y.upper() isn't flagged. What's surprising to me is that then, after x=y, x.upper() is flagged, saying that None doesn't have an upper attribute

No other type checker I tried reports on this

Spotted in Hypothesis

Sandbox Link

https://pyrefly.org/sandbox/?project=v2.pZRNDoIwEIWv0sgCXEj3nMIDkJgKFY2kEKCmvb1vBhr5UTYu275OpvO-vl-RSRZaQ5lSXm54-VUVz8QdMyEi2IvPSaGhaw-RooaxQATMsHHk1AR04vhjTggzFFh-wHVfoPV47qaBnPpSth7yAywO0tF3n9q21V1ynJ04FPFroVsJQ8Nhe2tsJM7jhphmhEgDEZXFDOB0mpsImanFfRjaPpMyXG-6Smojy6bo5eKGFMSweqkHx_GynGgYxB5l_yEqHoGK93iKCSdWnJTxEPEksM_FcbDLzhs

(Only applicable for extension issues) IDE Information

No response

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions