Skip to content

Non-overlapping identity check error for typing.get_origin #10405

Description

@eltoder

The following example produces an error in mypy --strict mode:

import typing

TypeSpec = typing.Any

def is_union(spec: TypeSpec) -> bool:
    return typing.get_origin(spec) is typing.Union

(it does work without the type alias).
This gives:

$ mypy --strict t.py
t.py:6: error: Non-overlapping identity check (left operand type: "type", right operand type: "<typing special form>")  [comparison-overlap]

It looks like get_origin() is declared to return type, but it can actually return some other things, notably Union and Literal.

mypy versions 1.4.1.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions