]> git.ipfire.org Git - thirdparty/psycopg.git/commit
Raise a TypeError when slice-setting a Multirange with a non-iterable value
authorDenis Laxalde <denis.laxalde@dalibo.com>
Thu, 28 Oct 2021 08:13:39 +0000 (10:13 +0200)
committerDaniele Varrazzo <daniele.varrazzo@gmail.com>
Thu, 28 Oct 2021 14:26:48 +0000 (15:26 +0100)
commit10ee2e90cdacf816c68cf8e44c4976dbc87b83bc
tree88e33f775276dc4712c04522d139c700401de3ba
parent609997a044a4b354ec8d454ab99bb8636467f8e2
Raise a TypeError when slice-setting a Multirange with a non-iterable value

The type declaration is:

    def __setitem__(index: slice, value: Iterable[Range[T]]) -> None:
        ...

so passing a non-iterable value should not be allowed. However, the
method implementation makes a special-case for non-iterable values with
a slice.

In accordance with MutableSequence behavior, e.g.:

  >>> x = [1, 2, 3]
  >>> x[1:3] = 0
  Traceback (most recent call last):
    File "<stdin>", line 1, in <module>
  TypeError: can only assign an iterable

it seems more correct to raise a TypeError.
docs/news.rst
psycopg/psycopg/types/multirange.py
tests/types/test_multirange.py