Skip to content

Dynamic properties in Typed Racket #7

Closed
@hanwenguo

Description

@hanwenguo

Consider the following Python Code:

class Node:
    def __init__(self) -> None:
        self.wins: int = 0
        # self.losses: int = 0
        self.parent: None | Node = None

    def score1(self) -> int:
        n = 0
        if self.parent is not None:
            n += self.parent.wins
        if self.parent is not None:
            n += self.parent.losses
        return n

    @property
    def losses(self):
        self.wins = 0
        self.parent = None
        return 0

    def score2(self) -> int:
        n = 0
        if self.parent is not None:
            n += self.losses
            n += self.parent.wins # no type error !?
        return n

n = Node()
m = Node()
n.parent = m
print(n.score2())

It suggests a unsound hole in the type system of Pyright and mypy (both of them suggest no type error as of 2024-10-22) due to dynamic properties performing operations on other properties. Does Racket has similar issues?

Metadata

Metadata

Assignees

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