Skip to content

Commit d1d681e

Browse files
committed
fields.py: Remove redundant parentheses and some other style/inspection fixes
1 parent 538a3d4 commit d1d681e

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

flask_mongoengine/wtf/fields.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
from wtforms import widgets as wtf_widgets
1515

1616

17+
# noinspection PyAttributeOutsideInit,PyAbstractClass
1718
class QuerySetSelectField(wtf_fields.SelectFieldBase):
1819
"""
1920
Given a QuerySet either at initialization or inside a view, will display a
@@ -54,7 +55,7 @@ def __init__(
5455

5556
def iter_choices(self):
5657
if self.allow_blank:
57-
yield ("__None", self.blank_text, self.data is None)
58+
yield "__None", self.blank_text, self.data is None
5859

5960
if self.queryset is None:
6061
return
@@ -71,7 +72,7 @@ def iter_choices(self):
7172
selected = obj in self.data
7273
else:
7374
selected = self._is_selected(obj)
74-
yield (obj.id, label, selected)
75+
yield obj.id, label, selected
7576

7677
def process_formdata(self, valuelist):
7778
if not valuelist or valuelist[0] == "__None" or self.queryset is None:
@@ -92,6 +93,7 @@ def _is_selected(self, item):
9293
return item == self.data
9394

9495

96+
# noinspection PyAttributeOutsideInit,PyAbstractClass
9597
class QuerySetSelectMultipleField(QuerySetSelectField):
9698
widget = wtf_widgets.Select(multiple=True)
9799

@@ -125,6 +127,7 @@ def _is_selected(self, item):
125127
return item in self.data if self.data else False
126128

127129

130+
# noinspection PyAttributeOutsideInit,PyAbstractClass
128131
class ModelSelectField(QuerySetSelectField):
129132
"""
130133
Like a QuerySetSelectField, except takes a model class instead of a
@@ -138,6 +141,7 @@ def __init__(self, label="", validators=None, model=None, **kwargs):
138141
)
139142

140143

144+
# noinspection PyAttributeOutsideInit,PyAbstractClass
141145
class ModelSelectMultipleField(QuerySetSelectMultipleField):
142146
"""
143147
Allows multiple select
@@ -150,6 +154,7 @@ def __init__(self, label="", validators=None, model=None, **kwargs):
150154
)
151155

152156

157+
# noinspection PyAttributeOutsideInit,PyAbstractClass
153158
class JSONField(wtf_fields.TextAreaField):
154159
def _value(self):
155160
# TODO: Investigate why raw mentioned.
@@ -162,8 +167,8 @@ def process_formdata(self, value):
162167
if value:
163168
try:
164169
self.data = json.loads(value[0])
165-
except ValueError:
166-
raise ValueError(self.gettext("Invalid JSON data."))
170+
except ValueError as error:
171+
raise ValueError(self.gettext("Invalid JSON data.")) from error
167172

168173

169174
class DictField(JSONField):
@@ -173,6 +178,7 @@ def process_formdata(self, value):
173178
raise ValueError(self.gettext("Not a valid dictionary."))
174179

175180

181+
# noinspection PyAttributeOutsideInit
176182
class NoneStringField(wtf_fields.StringField):
177183
"""
178184
Custom StringField that counts "" as None
@@ -185,6 +191,7 @@ def process_formdata(self, valuelist):
185191
self.data = None
186192

187193

194+
# noinspection PyAttributeOutsideInit
188195
class BinaryField(wtf_fields.TextAreaField):
189196
"""
190197
Custom TextAreaField that converts its value with binary_type.

0 commit comments

Comments
 (0)