Skip to content

Issue with constrained type var and Protocol #18024

Closed
@Redoubts

Description

@Redoubts

Bug Report

Seems like a regression from 11.2, consider the following

import gzip, shutil
from pathlib import Path


with open("/dev/null") as src, gzip.open("/dev/null", "wt") as dest:
    reveal_type(src)
    reveal_type(dest)
    shutil.copyfileobj(src, dest)


with Path("/dev/null").open() as src2, gzip.open("/dev/null", "wt") as dest2:
    reveal_type(src2)
    reveal_type(dest2)
    shutil.copyfileobj(src2, dest2)

I see errors even though this should be fine?

% mypy x.py     
x.py:6: note: Revealed type is "io.TextIOWrapper[io._WrappedBuffer]"
x.py:7: note: Revealed type is "typing.TextIO"
x.py:8: error: Cannot infer type argument 1 of "copyfileobj"  [misc]
x.py:12: note: Revealed type is "io.TextIOWrapper[io._WrappedBuffer]"
x.py:13: note: Revealed type is "typing.TextIO"
x.py:14: error: Cannot infer type argument 1 of "copyfileobj"  [misc]
Found 2 errors in 1 file (checked 1 source file)

no errors in 1.11.2:

x.py:6: note: Revealed type is "io.TextIOWrapper"
x.py:7: note: Revealed type is "typing.TextIO"
x.py:12: note: Revealed type is "io.TextIOWrapper"
x.py:13: note: Revealed type is "typing.TextIO"
Success: no issues found in 1 source file

Your Environment

  • Mypy version used: 1.13
  • Mypy command-line flags: mypy
  • Mypy configuration options from mypy.ini (and other config files): none
  • Python version used: Python 3.11.10

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