Merge ~andrey-fedoseev/lazr.restful:allow-none-for-lists into lazr.restful:main

Proposed by Andrey Fedoseev
Status: Merged
Merged at revision: 27df283b947ba7d52a4090c1dc782269fc09ecf7
Proposed branch: ~andrey-fedoseev/lazr.restful:allow-none-for-lists
Merge into: lazr.restful:main
Diff against target: 93 lines (+19/-5)
5 files modified
.pre-commit-config.yaml (+1/-1)
NEWS.rst (+5/-3)
setup.py (+1/-1)
src/lazr/restful/docs/webservice-marshallers.rst (+9/-0)
src/lazr/restful/marshallers.py (+3/-0)
Reviewer Review Type Date Requested Status
Colin Watson (community) Approve
Review via email: mp+423759@code.launchpad.net

Commit message

The collection marshallers can now unmarshall None

Description of the change

The collection marshallers (list, set, tuple) will now correctly
unmarshall `None` as `None`.

Previously, they would raise a `TypeError` when calling with `None`

To post a comment you must log in.
Revision history for this message
Colin Watson (cjwatson) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml
2index 6b363b1..4d505fe 100644
3--- a/.pre-commit-config.yaml
4+++ b/.pre-commit-config.yaml
5@@ -25,6 +25,6 @@ repos:
6 - id: pyupgrade
7 args: [--keep-percent-format, --py3-plus]
8 - repo: https://github.com/psf/black
9- rev: 21.10b0
10+ rev: 22.3.0
11 hooks:
12 - id: black
13diff --git a/NEWS.rst b/NEWS.rst
14index 6e42cce..d1817d2 100644
15--- a/NEWS.rst
16+++ b/NEWS.rst
17@@ -2,9 +2,10 @@
18 NEWS for lazr.restful
19 =====================
20
21-1.2.0
22-=====
23+2.0.0 (2022-06-01)
24+==================
25
26+- Drop Python 2 support.
27 - Add support for Python 3.9 and 3.10.
28 - Add basic pre-commit configuration.
29 - Publish docs on Read the Docs.
30@@ -19,7 +20,6 @@ NEWS for lazr.restful
31 ``lazr.restful.testing.webservice.DummyRootResourceURL``
32 => ``lazr.restful.testing.webservice.StubRootResourceURL``
33 - Apply black code formatter via pre-commit.
34-- Drop Python 2 support.
35 - Remove ``export_as_webservice_entry`` and
36 ``export_as_webservice_collection``; these were deprecated in 0.22.0 and
37 cannot work on Python 3. Use the class decorators
38@@ -27,6 +27,8 @@ NEWS for lazr.restful
39 ``@exported_as_webservice_collection`` instead.
40 - Deprecate ``lazr.restful.utils.safe_hasattr``, since Python's builtin
41 ``hasattr`` is fixed as of Python 3.2.
42+- The collection marshallers (list, set, tuple) will now correctly
43+ unmarshall ``None`` as ``None``.
44
45 1.1.0 (2021-10-07)
46 ==================
47diff --git a/setup.py b/setup.py
48index c21f37a..e8602b8 100755
49--- a/setup.py
50+++ b/setup.py
51@@ -38,7 +38,7 @@ def generate(*docname_or_string):
52
53 setup(
54 name="lazr.restful",
55- version="1.1.0",
56+ version="2.0.0",
57 namespace_packages=["lazr"],
58 packages=find_packages("src"),
59 package_dir={"": "src"},
60diff --git a/src/lazr/restful/docs/webservice-marshallers.rst b/src/lazr/restful/docs/webservice-marshallers.rst
61index b32e0d2..c99a36c 100644
62--- a/src/lazr/restful/docs/webservice-marshallers.rst
63+++ b/src/lazr/restful/docs/webservice-marshallers.rst
64@@ -984,6 +984,15 @@ The unmarshall() method will return None when given None.
65 >>> print(dict_marshaller.unmarshall(None, None))
66 None
67
68+ >>> print(list_marshaller.unmarshall(None, None))
69+ None
70+
71+ >>> print(set_marshaller.unmarshall(None, None))
72+ None
73+
74+ >>> print(tuple_marshaller.unmarshall(None, None))
75+ None
76+
77 CollectionField
78 ---------------
79
80diff --git a/src/lazr/restful/marshallers.py b/src/lazr/restful/marshallers.py
81index 3279657..2ca4e34 100644
82--- a/src/lazr/restful/marshallers.py
83+++ b/src/lazr/restful/marshallers.py
84@@ -511,6 +511,9 @@ class AbstractCollectionFieldMarshaller(SimpleFieldMarshaller):
85 The collection is unmarshalled into a list and all its items are
86 unmarshalled using the appropriate FieldMarshaller.
87 """
88+ if value is None:
89+ return value
90+
91 return [
92 self.value_marshaller.unmarshall(entry, item) for item in value
93 ]

Subscribers

People subscribed via source and target branches