8000 Allow assignment to new fields in class, mark the field as bound · Issue #726 · astral-sh/ty · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
8000
Allow assignment to new fields in class, mark the field as bound #726
Closed as not planned
@flexagoon

Description

@flexagoon

Summary

Not sure how else to title this issue, since this is two issues in one which relate to the same usecase.

class A:
    foo: int

class B:
    pass

def bar(p: A | B):
    p.foo = 4
    print(p.foo)

This produces two issues:

Object of type `Literal[4]` is not assignable to attribute `foo` on type `A | B` (invalid-assignment) [Ln 8, Col 5]
Attribute `foo` on type `A | B` is possibly unbound (possibly-unbound-attribute) [Ln 9, Col 11]

First of all, there should be a way to allow assignments like that via config.

But also, in this case, p.foo is guaranteed to be defined, so the possibly-unbound-attribute rule is a false positive.

Version

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    diagnosticsRelated to reporting of diagnostics.wishNot on the current roadmap; maybe in the future

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0