Quantcast
Channel: Recent Questions - Stack Overflow
Viewing all articles
Browse latest Browse all 12111

Mypy doesn't consider the if condition

$
0
0

I have a dictionary with different types, and in my code, while reading the dictionary through a loop, based on the type of it, I have different operations. The code is working as expected, but MYPY is complaining that it is incorrect. Here is the sample code:

COL = {"ABC": ["col1","col2","col3",    ],"BBC": ["col1","col2","col3",    ],"XYZ": {"col1": "c1","col2": "c2","col3": "c3",    },}list(COL[table_name].keys()) if isinstance(COL[table_name], dict) else COL[table_name]

Mypy reports the error: error: "Collection[str]" has no attribute "values"

It looks like the if condition was not taken into consideration.

Tried type annotations for COL but did not work.


Viewing all articles
Browse latest Browse all 12111

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>