python / python/mypy

discrepencay between mypy and mypyc

Open
#14,306 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug topic-mypyc
Dominant language
Python
Stars
20.6k
Forks
3.3k
PR merge metrics
PR metrics pending

Description

Bug Report

Code passes according to mypy but fails with mypyc.

To Reproduce

from pathlib import Path
from typing import TypeVar

PathNoneT = TypeVar("PathNoneT", Path, None)


def return_value(path: PathNoneT) -> PathNoneT:
    if path is None:
        return path
    new_path = path.with_suffix(".test")
    if not new_path.is_file() and path.is_file():
        new_path = path
    # mypyc: error: Incompatible return value type (got "Union[Path, Any]", expected "PathNoneT")  [return-value]
    return new_path

Expected Behavior

mypyc emits exactly the same errors as mypy.

Actual Behavior

Mypyc reports error: Incompatible return value type (got "Union[Path, Any]", expected "PathNoneT") [return-value] .

Your Environment

  • Mypy version used: 0.991
  • Python version used: 3.10.8
  • Mypy configuration options from mypy.ini (and other config files):

show_error_codes = true
enable_error_code = "ignore-without-code"
follow_imports = "silent"
warn_unused_configs = true
warn_redundant_casts = true
warn_unused_ignores = true
warn_no_return = true
no_implicit_optional = true
check_untyped_defs = true
disallow_incomplete_defs = true
disallow_untyped_defs = true
disallow_untyped_decorators = true
strict_equality = true

disallow_any_generics = false
ignore_missing_imports = true
warn_return_any = false

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the provided generic Path example with Python 3.10.8 and compare mypy's result with mypyc's diagnostic. Trace the type-checking path responsible for the differing return-value error; done means mypyc emits the same errors as mypy for this example.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.