diff options
author | Wojtek Kosior <koszko@koszko.org> | 2022-07-09 09:03:36 +0200 |
---|---|---|
committer | Wojtek Kosior <koszko@koszko.org> | 2022-07-09 09:03:36 +0200 |
commit | e55faf7dd0c13af4c4eaf94ebe0f2ae18799898a (patch) | |
tree | fd372e8d5686185ad06675f0d93dbe2c61ddd7dd /tests/test-data | |
parent | ca42184b18f521ac84ed98c371528af4ac2640e3 (diff) | |
parent | 9f7f7386c7fe49b249f6dd8c558266ce65e407dd (diff) | |
download | immutables-e55faf7dd0c13af4c4eaf94ebe0f2ae18799898a.tar.gz immutables-e55faf7dd0c13af4c4eaf94ebe0f2ae18799898a.zip |
Update upstream source from tag 'upstream/0.18'
Update to upstream version '0.18'
with Debian dir 4633953086f923825337301a18d98b4bc0c0e8b4
Diffstat (limited to 'tests/test-data')
-rw-r--r-- | tests/test-data/check-immu.test | 73 |
1 files changed, 73 insertions, 0 deletions
diff --git a/tests/test-data/check-immu.test b/tests/test-data/check-immu.test new file mode 100644 index 0000000..4998542 --- /dev/null +++ b/tests/test-data/check-immu.test @@ -0,0 +1,73 @@ +[case testMypyImmu] +# cmd: mypy test.py +[file test.py] +from immutables import Map +from typing import Dict, Union, Any, cast + +def init() -> None: + def thing(m: Map[str, Union[str, int]]) -> None: + ... + + thing(Map(foo=1)) + thing(Map(foo='bar', baz=1)) + thing(Map([('foo', 'bar'), ('bar', 1)])) + thing(Map(Map(foo=1), bar='foo')) + m = Map({1: 2}) + thing(m) # E: Argument 1 to "thing" has incompatible type "Map[int, int]"; expected "Map[str, Union[str, int]]" + +def assignments() -> None: + m_int__str = Map[int, str]() + m_str__str = Map[str, str]() + m_int_str__str = Map[Union[int, str], str]() + m_str__int_str = Map[str, Union[int, str]]() + + m_int__str = m_str__str # E: Incompatible types in assignment (expression has type "Map[str, str]", variable has type "Map[int, str]") + m_int__str = m_int_str__str # E: Incompatible types in assignment (expression has type "Map[Union[int, str], str]", variable has type "Map[int, str]") + m_int__str = m_str__int_str # E: Incompatible types in assignment (expression has type "Map[str, Union[int, str]]", variable has type "Map[int, str]") + + m_str__str = m_int__str # E: Incompatible types in assignment (expression has type "Map[int, str]", variable has type "Map[str, str]") + m_str__str = m_int_str__str # E: Incompatible types in assignment (expression has type "Map[Union[int, str], str]", variable has type "Map[str, str]") + m_str__str = m_str__int_str # E: Incompatible types in assignment (expression has type "Map[str, Union[int, str]]", variable has type "Map[str, str]") + + m_int_str__str = m_int__str # E: Incompatible types in assignment (expression has type "Map[int, str]", variable has type "Map[Union[int, str], str]") + m_int_str__str = m_str__str # E: Incompatible types in assignment (expression has type "Map[str, str]", variable has type "Map[Union[int, str], str]") + m_int_str__str = m_str__int_str # E: Incompatible types in assignment (expression has type "Map[str, Union[int, str]]", variable has type "Map[Union[int, str], str]") + + m_str__int_str = m_int__str # E: Incompatible types in assignment (expression has type "Map[int, str]", variable has type "Map[str, Union[int, str]]") + m_str__int_str = m_int_str__str # E: Incompatible types in assignment (expression has type "Map[Union[int, str], str]", variable has type "Map[str, Union[int, str]]") + m_str__int_str = m_str__str + +def update() -> None: + m_int__str: Map[int, str] = Map() + m_str__str: Map[str, str] = Map() + m_int_str__str: Map[Union[int, str], str] = Map() + m_str__int_str: Map[str, Union[int, str]] = Map() + + m_int__str.update({1: '2'}) + m_int__str.update({1: '2'}, three='4') # E: Unexpected keyword argument "three" for "update" of "Map" + m_int__str.update({1: 2}) # E: Argument 1 to "update" of "Map" has incompatible type "Dict[int, int]"; expected "Union[IterableItems[int, str], Iterable[Tuple[int, str]]]" + + m_str__str.update({'1': '2'}) + m_str__str.update({'1': '2'}, three='4') + m_str__str.update({'1': 2}) # E: Argument 1 to "update" of "Map" has incompatible type "Dict[str, int]"; expected "Union[IterableItems[str, str], Iterable[Tuple[str, str]]]" + + m_int_str__str.update(cast(Dict[Union[int, str], str], {1: '2', '3': '4'})) + m_int_str__str.update({1: '2'}, three='4') + m_int_str__str.update({'1': 2}) # E: Argument 1 to "update" of "Map" has incompatible type "Dict[str, int]"; expected "Union[IterableItems[Union[int, str], str], Iterable[Tuple[Union[int, str], str]]]" + + m_str__int_str.update({'1': 2, '2': 3}) + m_str__int_str.update({'1': 2, '2': 3}, four='5') + m_str__int_str.update({1: 2}) # E: Argument 1 to "update" of "Map" has incompatible type "Dict[int, int]"; expected "Union[IterableItems[str, Union[int, str]], Iterable[Tuple[str, Union[int, str]]]]" + +def mutate() -> None: + m = Map[str, str]() + + with m.mutate() as mm: + mm[0] = '1' # E: Invalid index type "int" for "MapMutation[str, str]"; expected type "str" + mm['1'] = 0 # E: Incompatible types in assignment (expression has type "int", target has type "str") + mm['1'] = '2' + del mm['1'] + mm.set('3', '4') + m2 = mm.finish() + + reveal_type(m2) # N: Revealed type is "immutables._map.Map[builtins.str*, builtins.str*]" |