8000 Regression: false positive avoid redundant cast with literal union · Issue #19055 · python/mypy · GitHub
[go: up one dir, main page]

Skip to content
Regression: false positive avoid redundant cast with literal union #19055
Open
@JukkaL

Description

@JukkaL

This example started generating an error after #18588, which looks like a regression:

# mypy: warn-redundant-casts

from typing import Literal, cast

Foo = Literal["a", "b"]

class C:
    def __init__(self) -> None:
        self.x = cast(Foo, "a")  # error: Redundant cast to "Literal['a', 'b']"

I haven't looked into this in detail, but it seems possible that we infer a union type for "a" in a literal union context, which doesn't look right. If this is a correct hypothesis, #18588 wouldn't actually be the root cause, and it would just be exposing a pre-existing issue.

cc @asottile as the author of the PR

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugmypy got something wrong

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0