File: utils.py

package info (click to toggle)
python-mashumaro 3.16-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,400 kB
  • sloc: python: 19,890; sh: 16; makefile: 5
file content (20 lines) | stat: -rw-r--r-- 767 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
from typing import ChainMap, Deque, List, Mapping, Set, Tuple


def same_types(first, second):
    if isinstance(first, (List, Deque, Tuple)):
        return all(map(lambda x: same_types(*x), zip(first, second)))
    elif isinstance(first, ChainMap):
        return all(map(lambda x: same_types(*x), zip(first.maps, second.maps)))
    elif isinstance(first, Mapping):
        return all(
            map(lambda x: same_types(*x), zip(first.keys(), second.keys()))
        ) and all(
            map(lambda x: same_types(*x), zip(first.values(), second.values()))
        )
    elif isinstance(first, Set):
        return all(
            map(lambda x: same_types(*x), zip(sorted(first), sorted(second)))
        )
    else:
        return type(first) is type(second)