Skip to content

Commit e4f2d2f

Browse files
committed
Fix lint. Apparently, we can complain about formating issues, but a human has to fix them.
Signed-off-by: Evan Anderson <evan.k.anderson@gmail.com>
1 parent 9892427 commit e4f2d2f

3 files changed

Lines changed: 30 additions & 23 deletions

File tree

cloudevents/sdk/event/base.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
# under the License.
1414

1515
import base64
16-
import io
1716
import json
1817
import typing
1918

@@ -194,7 +193,7 @@ def Set(self, key: str, value: object):
194193

195194
def MarshalJSON(self, data_marshaller: types.MarshallerType) -> str:
196195
if data_marshaller is None:
197-
data_marshaller = lambda x: x
196+
data_marshaller = lambda x: x # noqa: E731
198197
props = self.Properties()
199198
if "data" in props:
200199
data = data_marshaller(props.pop("data"))
@@ -217,7 +216,8 @@ def UnmarshalJSON(
217216

218217
for name, value in raw_ce.items():
219218
if name == "data":
220-
# Use the user-provided serializer, which may have customized JSON decoding
219+
# Use the user-provided serializer, which may have customized
220+
# JSON decoding
221221
value = data_unmarshaller(json.dumps(value))
222222
if name == "data_base64":
223223
value = data_unmarshaller(base64.b64decode(value))
@@ -227,21 +227,21 @@ def UnmarshalJSON(
227227
def UnmarshalBinary(
228228
self,
229229
headers: dict,
230-
body: typing.Union[bytes,str],
230+
body: typing.Union[bytes, str],
231231
data_unmarshaller: types.UnmarshallerType
232232
):
233233
if 'ce-specversion' not in headers:
234-
raise ValueError(f"Missing required attribute: 'specversion'")
234+
raise ValueError("Missing required attribute: 'specversion'")
235235
for header, value in headers.items():
236236
header = header.lower()
237237
if header == "content-type":
238238
self.SetContentType(value)
239239
elif header.startswith("ce-"):
240240
self.Set(header[3:], value)
241241
self.Set("data", data_unmarshaller(body))
242-
missing_attributes = self._ce_required_fields - self.Properties().keys()
243-
if len(missing_attributes) > 0:
244-
raise ValueError(f"Missing required attributes: {missing_attributes}")
242+
missing_attrs = self._ce_required_fields - self.Properties().keys()
243+
if len(missing_attrs) > 0:
244+
raise ValueError(f"Missing required attributes: {missing_attrs}")
245245

246246
def MarshalBinary(
247247
self,

cloudevents/sdk/http_events.py

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,25 +12,25 @@
1212
# License for the specific language governing permissions and limitations
1313
# under the License.
1414

15-
import copy
1615
import datetime
1716
import json
18-
import io
1917
import typing
2018
import uuid
2119

2220
from cloudevents.sdk import converters
2321
from cloudevents.sdk import marshaller
2422
from cloudevents.sdk import types
25-
from cloudevents.sdk.converters import binary
26-
from cloudevents.sdk.converters import structured
2723

2824
from cloudevents.sdk.event import v03, v1
2925

30-
_marshaller_by_format = {converters.TypeStructured: lambda x: x,
31-
converters.TypeBinary: json.dumps}
32-
_required_by_version = {"1.0": v1.Event._ce_required_fields,
33-
"0.3": v03.Event._ce_required_fields}
26+
_marshaller_by_format = {
27+
converters.TypeStructured: lambda x: x,
28+
converters.TypeBinary: json.dumps,
29+
}
30+
_required_by_version = {
31+
"1.0": v1.Event._ce_required_fields,
32+
"0.3": v03.Event._ce_required_fields,
33+
}
3434
_obj_by_version = {"1.0": v1.Event, "0.3": v03.Event}
3535

3636

@@ -61,7 +61,7 @@ def from_http(
6161
:type data: typing.IO
6262
:param headers: the HTTP headers
6363
:type headers: typing.Dict[str, str]
64-
:param data_unmarshaller: A function to decode data into a python object.
64+
:param data_unmarshaller: Function to decode data into a python object.
6565
:type data_unmarshaller: types.UnmarshallerType
6666
"""
6767
if data_unmarshaller is None:
@@ -76,7 +76,11 @@ def from_http(
7676

7777
return cls(attrs, event.data)
7878

79-
def __init__(self, attributes: typing.Dict[str, str], data: typing.Any = None):
79+
def __init__(
80+
self,
81+
attributes: typing.Dict[str, str],
82+
data: typing.Any = None
83+
):
8084
"""
8185
Event Constructor
8286
:param attributes: a dict with HTTP headers
@@ -104,7 +108,8 @@ def __init__(self, attributes: typing.Dict[str, str], data: typing.Any = None):
104108
if self._attributes['specversion'] not in _required_by_version:
105109
raise ValueError(
106110
f"Invalid specversion: {self._attributes['specversion']}")
107-
# There is no good way to default 'source' and 'type', so this checks for those.
111+
# There is no good way to default 'source' and 'type', so this
112+
# checks for those (or any new required attributes).
108113
required_set = _required_by_version[self._attributes['specversion']]
109114
if not required_set <= self._attributes.keys():
110115
raise ValueError(
@@ -120,7 +125,7 @@ def to_http(
120125
121126
:param format: constant specifying an encoding format
122127
:type format: str
123-
:param data_unmarshaller: callable function used to read the data io object
128+
:param data_unmarshaller: Function used to read the data to string.
124129
:type data_unmarshaller: types.UnmarshallerType
125130
:returns: (http_headers: dict, http_body: bytes or str)
126131
"""
@@ -135,7 +140,8 @@ def to_http(
135140
event.Set(k, v)
136141
event.data = self.data
137142

138-
return marshaller.NewDefaultHTTPMarshaller().ToRequest(event, format, data_marshaller)
143+
return marshaller.NewDefaultHTTPMarshaller().ToRequest(
144+
event, format, data_marshaller)
139145

140146
# Data access is handled via `.data` member
141147
# Attribute access is managed via Mapping type

cloudevents/sdk/types.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,6 @@
1919

2020
MarshallerType = typing.Optional[
2121
typing.Callable[[typing.Any], typing.Union[bytes, str]]]
22-
UnmarshallerType = typing.Optional[typing.Callable[[
23-
typing.Union[bytes, str]], typing.Any]]
22+
UnmarshallerType = typing.Optional[
23+
typing.Callable[
24+
[typing.Union[bytes, str]], typing.Any]]

0 commit comments

Comments
 (0)