Skip to content

Annotated assignments of non-name targets are not checked #509

@mtshiba

Description

@mtshiba

Summary

The following code passes without any errors.

l = []
l[0]: int = "foo"

class C:
    declared: int

c = C()
c.unresolved: int = "foo"
c.declared: str = "foo"

I thought these should be reported as type errors, but it seems that mypy and pyright treat such annotated assignments as "semantically invalid" and report errors without type checking.
In any case, since the current version of ty does not report any problems for this, some kind of fix should be made. In particular, the lack of checking for attribute existence (c.unresolved) is an obvious bug that should be fixed.

see also: microsoft/pylance-release#537

Version

ty 0.0.1a6 (ruff@83a036960)

Metadata

Metadata

Assignees

No one assigned

    Labels

    attribute accessInstance attributes, class attributes, etc.bugSomething isn't workingtyping semanticstyping-module features, spec compliance, etc

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions