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 shows object for values of large dictionaries #12831

Closed
PythonCoderAS opened this issue May 21, 2022 · 3 comments
Closed

Mypy shows object for values of large dictionaries #12831

PythonCoderAS opened this issue May 21, 2022 · 3 comments
Labels
bug mypy got something wrong topic-join-v-union Using join vs. using unions

Comments

@PythonCoderAS
Copy link

Bug Report

I have a large block of decently-nested JSON that I wrote types for using TypedDicts. I would like to verify that my types are correct by assigning a Python representation of one of the JSON blobs using the appropriate type variable. However, I am getting errors like

tests/test.py:15: error: Incompatible types in assignment (expression has type "Dict[str, List[List[object]]]", variable has type "SeriesVolumeCovers")

However, the value I am assigning is

{
    "covers": [
        [
            1,
            "/media/manga/Kaguya-Wants-To-Be-Confessed-To/volume_covers/1/1.png",
            "/media/manga/Kaguya-Wants-To-Be-Confessed-To/volume_covers/1/1.webp",
            "/media/manga/Kaguya-Wants-To-Be-Confessed-To/volume_covers/1/1_blur.png",
        ],
        [
            2,
            "/media/manga/Kaguya-Wants-To-Be-Confessed-To/volume_covers/2/2.png",
            "/media/manga/Kaguya-Wants-To-Be-Confessed-To/volume_covers/2/2.webp",
            "/media/manga/Kaguya-Wants-To-Be-Confessed-To/volume_covers/2/2_blur.png",
        ],
    ]
}

My types look like this:

SeriesVolumeCover = List[Union[str, int]]

class SeriesVolumeCovers(TypedDict):
    covers: List[SeriesVolumeCover]

The two should match, but for some reason mypy is complaining.

To Reproduce

  1. Create types like so:
from typing import List, Union, TypedDict

SeriesVolumeCover = List[Union[str, int]]

class SeriesVolumeCovers(TypedDict):
    covers: List[SeriesVolumeCover]
  1. Assign variable
data: SeriesVolumeCovers = {
    "covers": [
        [
            1,
            "/media/manga/Kaguya-Wants-To-Be-Confessed-To/volume_covers/1/1.png",
            "/media/manga/Kaguya-Wants-To-Be-Confessed-To/volume_covers/1/1.webp",
            "/media/manga/Kaguya-Wants-To-Be-Confessed-To/volume_covers/1/1_blur.png",
        ],
        [
            2,
            "/media/manga/Kaguya-Wants-To-Be-Confessed-To/volume_covers/2/2.png",
            "/media/manga/Kaguya-Wants-To-Be-Confessed-To/volume_covers/2/2.webp",
            "/media/manga/Kaguya-Wants-To-Be-Confessed-To/volume_covers/2/2_blur.png",
        ],
    ]
}

Expected Behavior

I expected the types to match.

Actual Behavior

The types did not match.

Your Environment

  • Mypy version used: 0.950
  • Mypy command-line flags: No flags
  • Mypy configuration options from mypy.ini (and other config files): No mypy.ini
  • Python version used: 3.9
  • Operating system and version: MacOS Big Sur/Ubuntu 20 LTS
@PythonCoderAS PythonCoderAS added the bug mypy got something wrong label May 21, 2022
@Zeckie
Copy link

Zeckie commented May 21, 2022

I tried to reproduce the issue on mypy playground, but needed to make a change (added an intermediate variable) to get the same error.

https://mypy-play.net/?mypy=0.950&python=3.9&gist=78d258e683165265cd6dada6dbee741d

This looks to me as though it is a known issue - topic-join-v-union Using join vs. using unions (eg. #12056 )

@PythonCoderAS
Copy link
Author

Oh yea in my actual test setup I did have an intermediate variable, as the python structure files were automatically generated

@JelleZijlstra JelleZijlstra added the topic-join-v-union Using join vs. using unions label May 21, 2022
@JelleZijlstra
Copy link
Member

Agree, this is another join-vs-union, we have plenty of open issues about that.

@JelleZijlstra JelleZijlstra closed this as not planned Won't fix, can't repro, duplicate, stale May 21, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug mypy got something wrong topic-join-v-union Using join vs. using unions
Projects
None yet
Development

No branches or pull requests

3 participants