Skip to content

Type of global variable is not narrowed in function scopes #311

@ion-elgreco

Description

@ion-elgreco

Summary

class Instance: ...

_instance: Instance | None = None

def get_instance() -> Instance:
    """Lazy static to get the instance"""
    global _instance
    if _instance is None:
        _instance = Instance()
    return _instance

https://play.ty.dev/f0b802a2-9e21-438d-8946-6386a45b45b5

We already checked that if it's None we assign a value to it, so the return value can't be possibly None anymore

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingnarrowingrelated to flow-sensitive type narrowing

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions