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

Incompatible types in assignment Tuple[bool, bool, bool, int] #6805

Closed
daevski opened this issue May 8, 2019 · 2 comments
Closed

Incompatible types in assignment Tuple[bool, bool, bool, int] #6805

daevski opened this issue May 8, 2019 · 2 comments

Comments

@daevski
Copy link

daevski commented May 8, 2019

  • Are you reporting a bug, or opening a feature request?
    Bug

  • Please insert below the code you are checking with mypy...

from typing import Tuple 

_behaviors = dict(headless=False, verbose=False,
                 dryrun=False, timeout=30)

print(type(_behaviors['headless']))  # bool
print(type(_behaviors['verbose']))  # bool
print(type(_behaviors['dryrun']))  # bool
print(type(_behaviors['timeout']))  # int

options: Tuple[bool, bool, bool, int] = (
        _behaviors['headless'], _behaviors['verbose'],
        _behaviors['dryrun'], _behaviors['timeout'])
  • What is the actual behavior/output?

sample.py:11: error: Incompatible types in assignment (expression has type "Tuple[int, int, int, int]", variable has type "Tuple[bool, bool, bool, int]")

  • What is the behavior/output you expect?
    I wouldn't expect mypy to see 'options' variable as Tuple[int, int, int, int], but rather Tuple[bool, bool, bool, int]

  • What are the versions of mypy and Python you are using?
    Python 3.7.1
    mypy 0.701

  • Do you see the same issue after installing mypy from Git master?
    yes

  • What are the mypy flags you are using? (For example --strict-optional)
    This occurs without any flags

Screenshot attached for some visuals. (The small script above is a simplified repro that still causes the error.)

mypy-possible-bug

@JelleZijlstra
Copy link
Member

This is because mypy infers the type of _behaviors as Dict[str, int] (bool is a subclass of int). This is similar to #3816.

In your case, you should probably be using a TypedDict or explicitly annotate _behaviors as Dict[str, Any].

@daevski
Copy link
Author

daevski commented May 8, 2019

Thank you. I knew I was missing something; it was too simple.

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

No branches or pull requests

2 participants