Skip to content

Support pipe operator for defining types in tests #18740

Open
@svalentin

Description

@svalentin

Tests in mypy don't support type unions with pipe operator.

In one of my mypyc PRs, I tried to write a test that used a type alias with pipe operator. Using Literal[<...>] | None in tests throwed this stack trace:

[...]
  File "/home/svalentin/src/mypy-svalentin/mypy/checkexpr.py", line 4890, in alias_type_in_runtime_context
    return self.chk.named_generic_type("types.UnionType", item.items)
           ~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/svalentin/src/mypy-svalentin/mypy/checker.py", line 7285, in named_generic_type
    info = self.lookup_typeinfo(name)
  File "/home/svalentin/src/mypy-svalentin/mypy/checker.py", line 7292, in lookup_typeinfo
    sym = self.lookup_qualified(fullname)
  File "/home/svalentin/src/mypy-svalentin/mypy/checker.py", line 7370, in lookup_qualified
    n = self.modules[parts[0]]
        ~~~~~~~~~~~~^^^^^^^^^^
KeyError: 'types'

Even with [typing fixtures/typing-full.pyi].
Test was in mypyc/test-data/irbuild-classes.test when I tried it.

We should provide a way for tests to be able to use type definitions like this, outside of Union[X, Y]

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions