Skip to content

can_be_true and can_be_false should be properties #11196

Closed
@sobolevn

Description

@sobolevn

Right now they are defined as:

        self.items = items
        self.can_be_true = len(self.items) > 0
        self.can_be_false = len(self.items) == 0

But, I can see a potential inconsistency here. Since items is writable and mutable (list), someone (let's say in a plugin) can add an item to Tuple, Union, or TypedDict without updating can_be_true and can_be_false attributes.

But, @propertys are dynamically computed, so it will always produce the correct result.
It is also used not-to-often, so it should not slow down the whole program.

I will send a PR with the proposed changes.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugmypy got something wrongrefactoringChanging mypy's internals

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions