Skip to content

add dedicated diagnostic code for "some elements of union missing attribute" #2839

@npaolini2634

Description

@npaolini2634

Starting in ty version 0.0.17 errors started popping up for instance attributes that start out as "None" and are assigned later.

class Test:
    def __init__(self):
        self.xxx = None
        self.fn_1()
        self.fn_2()

    def fn_1(self) -> None:
        self.xxx = 'populated'

    def fn_2(self) -> None:
        print(self.xxx.strip())  # <- Error if "unresolved-attribute" is enabled


# If "unresolved-attribute" is disabled, I won't see this real error
yyy = 1
print(yyy.strip())

I know it's possible to avoid these errors by performing a if self.xxx: check before using self.xxx, but for some scripts that involves littering the code with if self.xxx: checks, for little added value. It would be nice to have a rule to control this. Pyright has configuration flags such as "reportOptionalMemberAccess" to allow for this behavior, and mypy has "strict_optional".

EDIT - Is this supposed to be handled by ignoring possibly-missing-attribute? That doesn't seem to be ignoring these errors in version 0.0.17.

Still loving using ty, and appreciate all your hard work!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions