8000 typing.no_type_check is not understood · Issue #1448 · microsoft/pyright · GitHub
[go: up one dir, main page]

Skip to content

typing.no_type_check is not understood #1448

@earwig

Description

@earwig

Describe the bug
@typing.no_type_check is used to decorate functions that use annotations for other purposes than type hints. I have a code base that uses special annotations for certain functions (part of a DSL) and normal type annotations for other functions.

To reproduce

import typing

def foo(a: int) -> int:
    return "hello"

@typing.no_type_check
def bar(a: int) -> int:
    return "hello"

mypy handles this correctly, only complaining about foo:

example.py:4: error: Incompatible return value type (got "str", expected "int")
        return "hello"
               ^
Found 1 error in 1 file (checked 1 source file)

pyright additionally complains about the decorator itself and does not ignore the type annotations in bar:

  4:12 - error: Expression of type "Literal['hello']" cannot be assigned to return type "int"
    "Literal['hello']" is incompatible with "int" (reportGeneralTypeIssues)
  6:2 - error: Expected no arguments to "no_type_check" constructor (reportGeneralTypeIssues)
  8:12 - error: Expression of type "Literal['hello']" cannot be assigned to return type "int"
    "Literal['hello']" is incompatible with "int" (re

Expected behavior
@typing.no_type_check should cause type annotations for the decorated function to be ignored.

VS Code extension or command-line
Example above generated with CLI pyright 1.1.108, mypy 0.782, and Python 3.7, though I primarily use pyright through vim.

Additional context
You will notice that typeshed's typing.pyi defines no_type_check = object(), which might at first blush make this look like a bug in typeshed, but that is just typeshed's convention for marking special names that need explicit support in the typechecker. See python/mypy#645.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0