diff --git a/docs/reference/array.md b/docs/reference/array.md index b3d43562..bbabc5a3 100644 --- a/docs/reference/array.md +++ b/docs/reference/array.md @@ -2,7 +2,12 @@ # Typed Array +Integer indexing preserves the element type: `TypedArray[int]([1, 2])[0]` +has type `int`. Slice indexing returns the underlying storage's mutable sequence, +not another `TypedArray`. Type checking also checks individual assignments and +slice replacement elements against the array's element type. + ```{eval-rst} .. automodule:: expression.collections.array :members: -``` \ No newline at end of file +``` diff --git a/docs/reference/collections.md b/docs/reference/collections.md index 8860018e..4101281f 100644 --- a/docs/reference/collections.md +++ b/docs/reference/collections.md @@ -14,6 +14,12 @@ while `skip_last(0)` preserves all elements. For example, `AsyncSeq.take(n)` consumes at most `n` source items. Taking zero items does not advance the source, and completing the result does not request an extra item. +`sum` and `sum_by` use Python's summation behavior: empty input returns integer +`0`, even when the element or projection type is `float` or `Decimal`. Their +return annotations include this empty-input case. `sum_by` requires summable +projection results, not summable source elements; for example, +`Block.of("one", "four").sum_by(len)` returns `7`. + ## Additional modules ```{eval-rst} diff --git a/expression/collections/array.py b/expression/collections/array.py index 426a28b0..14d20ca4 100644 --- a/expression/collections/array.py +++ b/expression/collections/array.py @@ -12,9 +12,10 @@ import array import builtins import functools +import operator from collections.abc import Callable, Iterable, Iterator, MutableSequence from enum import Enum -from typing import Any, cast +from typing import Any, Literal, SupportsIndex, cast, overload from expression.core import ( NOTHING, @@ -30,7 +31,7 @@ from . import seq -type _Array[TSourceSum: SupportsSum] = list[TSourceSum] | MutableSequence[TSourceSum] +type _Array[TSource] = MutableSequence[TSource] class int8(int): ... @@ -174,7 +175,7 @@ def __init__( else: arr, typecode = array_from_initializer(initializer) - self.value: _Array[Any] = arr + self.value: _Array[TSource] = arr self.typecode = typecode def map[TResult](self, mapping: Callable[[TSource], TResult]) -> TypedArray[TResult]: @@ -364,10 +365,10 @@ def sort_with(self, func: Callable[[TSource], Any], reverse: bool = False) -> Ty """ return TypedArray(builtins.sorted(self.value, key=func, reverse=reverse)) - def sum[TSourceSum: SupportsSum](self: TypedArray[TSourceSum]) -> int: + def sum[TSourceSum: SupportsSum](self: TypedArray[TSourceSum]) -> TSourceSum | Literal[0]: return sum(self) - def sum_by[TSourceSum: SupportsSum](self, projection: Callable[[TSource], TSourceSum]) -> int: + def sum_by[TSourceSum: SupportsSum](self, projection: Callable[[TSource], TSourceSum]) -> TSourceSum | Literal[0]: return pipe( self, sum_by(projection), @@ -410,13 +411,13 @@ def try_head(self) -> Option[TSource]: empty. """ if self.value: - value = cast("TSource", self.value[0]) + value = self.value[0] return Some(value) return NOTHING @staticmethod - def unfold[TResult, TState]( + def unfold[TState, TResult]( generator: Callable[[TState], Option[tuple[TResult, TState]]], state: TState ) -> TypedArray[TResult]: """Unfold array. @@ -451,11 +452,26 @@ def __len__(self) -> int: def __iter__(self) -> Iterator[TSource]: return iter(self.value) - def __setitem__(self, key: slice | int, value: Any) -> None: - self.value[key] = value + @overload + def __setitem__(self, key: SupportsIndex, value: TSource) -> None: ... - def __getitem__(self, key: Any) -> Any: - return self.value[key] + @overload + def __setitem__(self, key: slice, value: Iterable[TSource]) -> None: ... + + def __setitem__(self, key: slice | SupportsIndex, value: TSource | Iterable[TSource]) -> None: + if isinstance(key, slice): + self.value[key] = cast(Iterable[TSource], value) + else: + self.value[operator.index(key)] = cast(TSource, value) + + @overload + def __getitem__(self, key: SupportsIndex) -> TSource: ... + + @overload + def __getitem__(self, key: slice) -> MutableSequence[TSource]: ... + + def __getitem__(self, key: slice | SupportsIndex) -> TSource | MutableSequence[TSource]: + return self.value[key] if isinstance(key, slice) else self.value[operator.index(key)] def __delitem__(self, key: slice | int) -> None: del self.value[key] @@ -575,14 +591,14 @@ def singleton[TSource](value: TSource) -> TypedArray[TSource]: return TypedArray((value,)) -def sum[TSourceSum: SupportsSum](source: TypedArray[TSourceSum]) -> int: +def sum[TSourceSum: SupportsSum](source: TypedArray[TSourceSum]) -> TSourceSum | Literal[0]: return builtins.sum(source.value) @curry_flip(1) def sum_by[TSource, TSourceSum: SupportsSum]( source: TypedArray[TSource], projection: Callable[[TSource], TSourceSum] -) -> int: +) -> TSourceSum | Literal[0]: return builtins.sum(source.map(projection).value) diff --git a/expression/collections/asyncseq.py b/expression/collections/asyncseq.py index 18de7854..c6917af3 100644 --- a/expression/collections/asyncseq.py +++ b/expression/collections/asyncseq.py @@ -14,7 +14,7 @@ def __init__(self, ai: AsyncIterable[TSource]): async def map[TResult](self, mapper: Callable[[TSource], TResult]) -> "AsyncSeq[TResult]": # Use the module-level `map` function defined later to transform the # underlying async iterable and wrap the result back into an AsyncSeq. - return AsyncSeq(pipe(self._ai, map(mapper))) # type: ignore[arg-type] + return AsyncSeq(pipe(self._ai, map(mapper))) @classmethod def empty(cls) -> "AsyncSeq[Any]": @@ -279,7 +279,7 @@ async def _filter(source: AsyncIterable[TSource]) -> AsyncIterable[TSource]: return _filter -def map[TResult, TSource]( +def map[TSource, TResult]( mapper: Callable[[TSource], TResult], ) -> Callable[[AsyncIterable[TSource]], AsyncIterable[TResult]]: async def _map(source: AsyncIterable[TSource]) -> AsyncIterable[TResult]: diff --git a/expression/collections/block.py b/expression/collections/block.py index fbea001e..5ec28499 100644 --- a/expression/collections/block.py +++ b/expression/collections/block.py @@ -261,9 +261,7 @@ def starmap[*P, TResult](self: Block[tuple[*P]], mapping: Callable[[Unpack[P]], def sum[TSourceSum: SupportsSum](self: Block[TSourceSum | Literal[0]]) -> TSourceSum | Literal[0]: return builtins.sum(self._value) - def sum_by[TSourceSum: SupportsSum, TResult]( - self: Block[TSourceSum], projection: Callable[[TSourceSum], TResult] - ) -> TResult: + def sum_by[TResult: SupportsSum](self, projection: Callable[[_TSource], TResult]) -> TResult | Literal[0]: return pipe(self, sum_by(projection)) def mapi[TResult](self, mapping: Callable[[int, _TSource], TResult]) -> Block[TResult]: @@ -462,7 +460,7 @@ def try_head(self) -> Option[_TSource]: return NOTHING @staticmethod - def unfold[TResult, TState]( + def unfold[TState, TResult]( generator: Callable[[TState], Option[tuple[TResult, TState]]], state: TState ) -> Block[TResult]: """Unfold block. @@ -759,7 +757,7 @@ def reduce[TSource]( return source.tail().fold(reduction, source.head()) -def starmap[TResult, *P](mapper: Callable[[Unpack[P]], TResult]) -> Callable[[Block[tuple[*P]]], Block[TResult]]: +def starmap[*P, TResult](mapper: Callable[[Unpack[P]], TResult]) -> Callable[[Block[tuple[*P]]], Block[TResult]]: """Starmap source sequence. Unpack arguments grouped as tuple elements. Builds a new collection @@ -779,13 +777,13 @@ def mapper_(args: tuple[*P]) -> TResult: return map(mapper_) -def map2[TResult, T1, T2]( +def map2[T1, T2, TResult]( mapper: Callable[[T1, T2], TResult], ) -> Callable[[Block[tuple[T1, T2]]], Block[TResult]]: return starmap(mapper) -def map3[TResult, T1, T2, T3]( +def map3[T1, T2, T3, TResult]( mapper: Callable[[T1, T2, T3], TResult], ) -> Callable[[Block[tuple[T1, T2, T3]]], Block[TResult]]: return starmap(mapper) @@ -937,11 +935,11 @@ def sum[TSourceSum: SupportsSum](source: Block[TSourceSum | Literal[0]]) -> TSou @curry_flip(1) -def sum_by[TSourceSum: SupportsSum, TResult]( - source: Block[TSourceSum], projection: Callable[[TSourceSum], TResult] -) -> TResult: +def sum_by[TSource, TResult: SupportsSum]( + source: Block[TSource], projection: Callable[[TSource], TResult] +) -> TResult | Literal[0]: xs = source.map(projection) - return builtins.sum(xs) # type: ignore + return builtins.sum(xs) def tail[TSource](source: Block[TSource]) -> Block[TSource]: diff --git a/expression/collections/seq.py b/expression/collections/seq.py index d5492148..2a7376e4 100644 --- a/expression/collections/seq.py +++ b/expression/collections/seq.py @@ -28,7 +28,7 @@ import functools import itertools from collections.abc import Callable, Iterable, Iterator -from typing import TYPE_CHECKING, Any, cast, overload +from typing import TYPE_CHECKING, Any, Literal, cast, overload from expression.core import ( NOTHING, @@ -281,11 +281,13 @@ def skip(self, count: int) -> Seq[TSource]: """ return Seq(pipe(self, skip(count))) - def sum[TSupportsSum: SupportsSum](self: Seq[TSupportsSum]) -> TSupportsSum: + def sum[TSupportsSum: SupportsSum](self: Seq[TSupportsSum]) -> TSupportsSum | Literal[0]: """Returns the sum of the elements in the sequence.""" return sum(self) - def sum_by[TSupportsSum: SupportsSum](self, projection: Callable[[TSource], TSupportsSum]) -> TSupportsSum: + def sum_by[TSupportsSum: SupportsSum]( + self, projection: Callable[[TSource], TSupportsSum] + ) -> TSupportsSum | Literal[0]: """Sum the sequence by projection. Returns the sum of the results generated by applying the @@ -346,7 +348,7 @@ def to_obj(value: Any) -> Any: return (to_obj(value) for value in self) @classmethod - def unfold[TResult, TState]( + def unfold[TState, TResult]( cls, generator: Callable[[TState], Option[tuple[TResult, TState]]], state: TState, @@ -700,19 +702,19 @@ def gen(): @overload -def starmap[TResult, T1, T2]( +def starmap[T1, T2, TResult]( mapper: Callable[[T1, T2], TResult], ) -> Callable[[Iterable[tuple[T1, T2]]], Iterable[TResult]]: ... @overload -def starmap[TResult, T1, T2, T3]( +def starmap[T1, T2, T3, TResult]( mapper: Callable[[T1, T2, T3], TResult], ) -> Callable[[Iterable[tuple[T1, T2, T3]]], Iterable[TResult]]: ... @overload -def starmap[TResult, T1, T2, T3, T4]( +def starmap[T1, T2, T3, T4, TResult]( mapper: Callable[[T1, T2, T3, T4], TResult], ) -> Callable[[Iterable[tuple[T1, T2, T3, T4]]], Iterable[TResult]]: ... @@ -737,13 +739,13 @@ def mapper_(args: tuple[Any, ...]) -> Any: return map(mapper_) -def map2[TResult, T1, T2]( +def map2[T1, T2, TResult]( mapper: Callable[[T1, T2], TResult], ) -> Callable[[Iterable[tuple[T1, T2]]], Iterable[TResult]]: return starmap(mapper) -def map3[TResult, T1, T2, T3]( +def map3[T1, T2, T3, TResult]( mapper: Callable[[T1, T2, T3], TResult], ) -> Callable[[Iterable[tuple[T1, T2, T3]]], Iterable[TResult]]: return starmap(mapper) @@ -908,16 +910,15 @@ def gen(): return SeqGen(gen) -def sum[TSupportsSum: SupportsSum](source: Iterable[TSupportsSum]) -> TSupportsSum: +def sum[TSupportsSum: SupportsSum](source: Iterable[TSupportsSum]) -> TSupportsSum | Literal[0]: """Returns the sum of the elements in the sequence.""" - ret = builtins.sum(source) - return cast(TSupportsSum, ret) + return builtins.sum(source) @curry_flip(1) def sum_by[TSource, TSupportsSum: SupportsSum]( source: Iterable[TSource], projection: Callable[[TSource], TSupportsSum] -) -> TSupportsSum: +) -> TSupportsSum | Literal[0]: """Sum all elements in sequence. Returns the sum of the results generated by applying the function to diff --git a/expression/core/aiotools.py b/expression/core/aiotools.py index 5853df1f..b6279f45 100644 --- a/expression/core/aiotools.py +++ b/expression/core/aiotools.py @@ -99,12 +99,12 @@ def cleanup(completed: Task[TSource]) -> None: return task -def start(computation: Awaitable[Any], token: CancellationToken | None = None) -> None: +def start(computation: Awaitable[object], token: CancellationToken | None = None) -> None: """Schedule a computation on the running event loop.""" _start_task(computation, token) -def start_immediate(computation: Awaitable[Any], token: CancellationToken | None = None) -> None: +def start_immediate(computation: Awaitable[object], token: CancellationToken | None = None) -> None: """Schedule a computation on the running event loop. Execution begins when the event loop next runs the task. diff --git a/expression/core/misc.py b/expression/core/misc.py index 8dddeeb8..0d546ca7 100644 --- a/expression/core/misc.py +++ b/expression/core/misc.py @@ -1,5 +1,4 @@ from collections.abc import Callable -from typing import Any def identity[A](value: A) -> A: @@ -14,26 +13,26 @@ def starid[*P](*value: *P) -> tuple[*P]: return value -def flip[TResult, A, B](fn: Callable[[A, B], TResult]) -> Callable[[B, A], TResult]: +def flip[A, B, TResult](fn: Callable[[A, B], TResult]) -> Callable[[B, A], TResult]: """Flips the arguments for a function taking two arguments. Example: >>> fn(a, b) == flip(fn)(b, a) """ - def _flip(b: B, a: A) -> Any: + def _flip(b: B, a: A) -> TResult: return fn(a, b) return _flip -def snd[TSource](value: tuple[Any, TSource]) -> TSource: +def snd[TSource](value: tuple[object, TSource]) -> TSource: """Return second argument of the tuple.""" _, b = value return b -def fst[TSource](value: tuple[TSource, Any]) -> TSource: +def fst[TSource](value: tuple[TSource, object]) -> TSource: """Return first argument of the tuple.""" a, _ = value return a diff --git a/expression/core/option.py b/expression/core/option.py index b142edb4..6c52c460 100644 --- a/expression/core/option.py +++ b/expression/core/option.py @@ -63,7 +63,7 @@ def map[TResult](self, mapper: Callable[[_TSourceOut], TResult]) -> Some[TResult """Transform the present value.""" return Some(mapper(self.some)) - def map2[TResult, T2](self, mapper: Callable[[_TSourceOut, T2], TResult], other: Option[T2]) -> Option[TResult]: + def map2[T2, TResult](self, mapper: Callable[[_TSourceOut, T2], TResult], other: Option[T2]) -> Option[TResult]: """Transform two present values, or return Nothing.""" return other.map(lambda value: mapper(self.some, value)) @@ -339,12 +339,12 @@ def apply(function: Nothing) -> Callable[[Option[object]], Nothing]: ... @overload -def apply[TResult, TSource]( +def apply[TSource, TResult]( function: Option[Callable[[TSource], TResult]], ) -> Callable[[Option[TSource]], Option[TResult]]: ... -def apply[TResult, TSource]( +def apply[TSource, TResult]( function: Option[Callable[[TSource], TResult]], ) -> Callable[[Option[TSource]], Option[TResult]]: """Apply an optional function to an optional value.""" diff --git a/expression/core/typing.py b/expression/core/typing.py index 169f6a15..6549c0a3 100644 --- a/expression/core/typing.py +++ b/expression/core/typing.py @@ -60,7 +60,7 @@ def upcast[Base](type: type[Base], expr: Base) -> Base: return expr -def downcast[Derived](type: type[Derived], expr: Any) -> Derived: +def downcast[Derived](type: type[Derived], expr: object) -> Derived: """Downcast expression `Derived` to `Base`. Checks at compile time that the type of expression Base is a @@ -73,7 +73,7 @@ def downcast[Derived](type: type[Derived], expr: Any) -> Derived: return expr -def try_downcast[Derived](type_: type[Derived], expr: Any) -> Derived | None: +def try_downcast[Derived](type_: type[Derived], expr: object) -> Derived | None: """Downcast expression `Base` to `Derived`. Check that the `Derived` type is a supertype of `Base`. diff --git a/expression/extra/result/traversable.py b/expression/extra/result/traversable.py index 11839e43..171891b8 100644 --- a/expression/extra/result/traversable.py +++ b/expression/extra/result/traversable.py @@ -1,9 +1,7 @@ """Data structures that can be traversed from left to right, performing an action on each element.""" from collections.abc import Callable -from typing import Any, cast -from expression import effect from expression.collections import Block, block, seq from expression.core import Ok, Result, identity, pipe @@ -16,18 +14,13 @@ def traverse[TSource, TResult, TError]( Threads an applicative computation though a list of items. """ - @effect.result[Block[TResult], TError]() - def folder(head: TSource, tail: Result[Block[TResult], TError]) -> Any: - """Fold back function. + def folder(head: TSource, tail: Result[Block[TResult], TError]) -> Result[Block[TResult], TError]: + """Prepend a successful result, preserving the first error in input order.""" - Same as: - >>> fn(head).bind(lambda head: tail.bind(lambda tail: Ok([head] + tail))). - """ - # Pyright #11881 loses the return type for a union of iterable cases. - h = cast(TResult, (yield from fn(head))) - t = cast(Block[TResult], (yield from tail)) + def prepend(h: TResult) -> Result[Block[TResult], TError]: + return tail.map(lambda t: Block([h]) + t) - return Block([h]) + t + return fn(head).bind(prepend) state: Result[Block[TResult], TError] = Ok(block.empty) ret = pipe( diff --git a/tests/test_array.py b/tests/test_array.py index 3794672a..e42f8fa9 100644 --- a/tests/test_array.py +++ b/tests/test_array.py @@ -435,3 +435,37 @@ def test_array_trailing_zero_count(): assert list(source.take_last(0)) == [] assert list(pipe(source, array.take_last(0))) == [] assert list(source.skip_last(0)) == [1, 2, 3] + + +def test_array_typed_index_and_slice_assignment(): + class Index: + def __index__(self) -> int: + return 1 + + values = TypedArray[int]([1, 2, 3]) + assert values[Index()] == 2 + values[Index()] = 4 + values[1:] = [5, 6] + assert list(values) == [1, 5, 6] + assert list(values[1:]) == [5, 6] + + +def test_array_numeric_storage_indexing(): + values = TypedArray[int]([1, 2, 3], typecode=array.TypeCode.Int32) + values[1] = 4 + assert values[1] == 4 + assert list(values[1:]) == [4, 3] + bytes_values = TypedArray[int](bytearray([1, 2])) + bytes_values[0] = 3 + assert list(bytes_values[:]) == [3, 2] + + +def test_array_sum_preserves_projection_type_and_empty_zero(): + from decimal import Decimal + + values = TypedArray[str](["1.5", "2.5"]) + assert values.sum_by(Decimal) == Decimal("4") + assert TypedArray[Decimal]([Decimal("1.5")]).sum() == Decimal("1.5") + result = TypedArray[int]().sum_by(float) + assert result == 0 + assert type(result) is int diff --git a/tests/test_block.py b/tests/test_block.py index 101020ec..9af38ae5 100644 --- a/tests/test_block.py +++ b/tests/test_block.py @@ -504,3 +504,15 @@ def test_block_trailing_zero_count(): assert list(pipe(source, block.take_last(0))) == [] assert list(source.skip_last(0)) == [1, 2, 3] assert list(pipe(source, block.skip_last(0))) == [1, 2, 3] + + +def test_block_sum_by_non_numeric_source(): + words = Block(["one", "four"]) + assert words.sum_by(len) == 7 + assert pipe(words, block.sum_by(len)) == 7 + + +def test_block_sum_by_empty_returns_integer_zero(): + result = Block[int]().sum_by(float) + assert result == 0 + assert type(result) is int diff --git a/tests/test_misc.py b/tests/test_misc.py new file mode 100644 index 00000000..a0092618 --- /dev/null +++ b/tests/test_misc.py @@ -0,0 +1,21 @@ +from typing import assert_type + +from expression.core.misc import flip, fst, snd + + +def test_flip_preserves_argument_and_result_types(): + def repeat(text: str, count: int) -> str: + return text * count + + flipped = flip(repeat) + assert assert_type(flipped(3, "ab"), str) == "ababab" + + +def test_fst_preserves_selected_type(): + pair: tuple[int, str] = (42, "answer") + assert assert_type(fst(pair), int) == 42 + + +def test_snd_preserves_selected_type(): + pair: tuple[int, str] = (42, "answer") + assert assert_type(snd(pair), str) == "answer" diff --git a/tests/test_result.py b/tests/test_result.py index 52842ed4..c54e820a 100644 --- a/tests/test_result.py +++ b/tests/test_result.py @@ -776,3 +776,16 @@ def add(left: int, right: int) -> int: assert result.map2(add)(Ok(2))(Error("second")) == Error("second") assert Error("value").pipe(result.apply(Error("function"))) == Error("function") assert Ok(2).pipe(result.apply(Error("function"))) == Error("function") + + +def test_traverse_preserves_order_and_first_error(): + from expression.extra.result import traverse + + visited: list[int] = [] + + def check(value: int) -> Result[str, str]: + visited.append(value) + return Error(str(value)) if value < 3 else Ok(str(value)) + + assert traverse(check, Block([1, 2, 3])) == Error("1") + assert visited == [3, 2, 1] diff --git a/tests/test_seq.py b/tests/test_seq.py index 7691b494..d25c1e72 100644 --- a/tests/test_seq.py +++ b/tests/test_seq.py @@ -576,3 +576,13 @@ class IntSeq(Seq[int]): values = IntSeq.of_iterable([1, 2, 3]) assert isinstance(values, IntSeq) assert list(values) == [1, 2, 3] + + +def test_seq_sum_preserves_projection_type_and_empty_zero(): + from decimal import Decimal + + assert seq.sum_by(Decimal)(["1.5", "2.5"]) == Decimal("4") + assert seq.sum([Decimal("1.5")]) == Decimal("1.5") + result = seq.sum_by(float)([]) + assert result == 0 + assert type(result) is int diff --git a/tests/typing_contracts.py b/tests/typing_contracts.py index f1848dd1..df71d48c 100644 --- a/tests/typing_contracts.py +++ b/tests/typing_contracts.py @@ -239,3 +239,31 @@ def computation_contracts() -> None: async def await_contracts(option_value: Option[int], result_value: Result[int, str]) -> None: assert_type(await option_value, int) assert_type(await result_value, int) + + +def collection_sum_and_index_contract() -> None: + from collections.abc import MutableSequence + + from expression.collections import array, block, seq + + def length(value: str) -> int: + return len(value) + + def as_float(value: int) -> float: + return float(value) + + words = Block(["one", "two"]) + assert_type(words.sum_by(len), int) + assert_type(block.sum_by(length)(words), int) + assert_type(Block[int]().sum_by(float), float | Literal[0]) + assert_type(Seq[int]().sum_by(float), float | Literal[0]) + assert_type(seq.sum_by(float)([]), float | Literal[0]) + assert_type(TypedArray[int]().sum_by(float), float | Literal[0]) + assert_type(array.sum_by(as_float)(TypedArray[int]()), float | Literal[0]) + assert_type(Seq[float]().sum(), float | Literal[0]) + assert_type(TypedArray[float]().sum(), float | Literal[0]) + values = TypedArray[int]([1, 2]) + assert_type(values[0], int) + assert_type(values[:], MutableSequence[int]) + values[0] = 3 + values[:] = [4, 5] diff --git a/typing_tests/negative.py b/typing_tests/negative.py index 46b160e0..cf67394f 100644 --- a/typing_tests/negative.py +++ b/typing_tests/negative.py @@ -161,3 +161,11 @@ def catch_source(value: int, *, suffix: str) -> str: caught_direct(1, "!") # type-error caught_decorated(1) # type-error catch(ValueError) # type-error + + +# Collection element types and summation projections remain checked. +integers = TypedArray[int]([1, 2]) +integers[0] = "wrong" # type-error +integers[:] = ["wrong"] # type-error +integers["wrong"] # type-error +Block([1]).sum_by(str) # type-error