Skip to content

report unsafe __get__ return types #1175

@KotlinIsland

Description

@KotlinIsland

Describe the Bug

descriptors can be unsafe:

class A: 
    pass

class B(A):
    def __get__(self, *_) -> 1:
        return 1

class C:
    a: A = B()

C.a  # static: A, runtime: 1

we can avoid this by reporting an error on the signature of __get__: "__get__s return type must be assignable to the super classes __get__ (defaulting to the type of the superclass in it's absense)"

the same applies to __set__

Sandbox Link

No response

(Only applicable for extension issues) IDE Information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    needs-discussionAn issue where it's not clear whether there is a bug or we are behaving as expected.typechecking

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions