Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mypy not treating an empty Dict in a tuple as matching Iterable[Dict[..., ...]] #11625

Closed
sethmlarson opened this issue Nov 26, 2021 · 3 comments
Labels
bug mypy got something wrong

Comments

@sethmlarson
Copy link

sethmlarson commented Nov 26, 2021

Bug Report

Mypy is treating an empty dictionary in a tuple differently than an empty dictionary in other collections when it comes to matching Iterable[Dict[..., ...]].

Expected Behavior

With the given file:

from typing import Iterable, Dict, Any


def f(x: Iterable[Dict[str, str]]) -> None:
    pass


# Lists all work as expected
f([])
f([{}])
f([{"k": "v"}])

# Empty tuple works
f(())

# Tuple of empty dict doesn't work
f(({},))

# Tuple with non-empty dict works
f(({"k": "v"},))

and running mypy with --strict you should receive no errors because Tuple[Dict[empty]] should match Iterable[Dict[str, str]].

Actual Behavior

$ mypy --strict testme.py 
testme.py:17: error: Argument 1 to "f" has incompatible type "Tuple[Dict[<nothing>, <nothing>]]"; expected "Iterable[Dict[str, str]]"
Found 1 error in 1 file (checked 1 source file)

which is erroring out on this line:

f(({},))

Your Environment

  • Mypy version used: 0.910
  • Mypy command-line flags: --strict
  • Python version used: 3.8.6
  • Operating system and version: Ubuntu 20.04

This is potentially related to #6613 where an empty collection isn't matching a collection type?

@sethmlarson sethmlarson added the bug mypy got something wrong label Nov 26, 2021
@JelleZijlstra
Copy link
Member

Also similar to #11618 (I suspect @hauntsaninja's explanation there applies here too).

@erictraut
Copy link

This bug appears to have been fixed. I'm not able to repro it with mypy 1.5.

@hauntsaninja
Copy link
Collaborator

Fixed by #13406

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug mypy got something wrong
Projects
None yet
Development

No branches or pull requests

4 participants