if
statements can be merged PTC-W004818 def update_filters(self):
19 filters = []
20
21 if self.meta:22 if hasattr(self.meta, 'model'):
23 Model = self.meta.model
24 mapper = inspect(Model)
97 instance = self.create_instance(validated_data)
98 self.session.add(instance)
99
100 if primary_key.autoincrement and primary_key_specified:101 if get_session_engine(self.session) == 'postgresql':
102 self.session.execute('''
103 SELECT
38
39
40def map_column_default(column):
41 if column.server_default is not None: 42 if hasattr(column.server_default, 'arg') and isinstance(column.server_default.arg, TextClause):
43 value = column.server_default.arg.text
44 if value.lower() == 'now()':
115 for field in self.writable_fields:
116 field_value = field.get_value(value)
117
118 if field_value is empty:119 if self.partial or not field.required:
120 continue
121
73 return list(filter(lambda x: not x.read_only, self.fields))
74
75 def run_validation(self, value):
76 if value is empty: 77 if self.required:
78 # raise ValidationError('Field is required')
79 self.error('required')
Nested if
statements can be collapsed into a single if
statement by separating their condition using and
operator.
Merging collapsible if
statements increases the code's readability.
if condition1:
if condition2:
dosomething()
if condition1 and condition2:
dosomething()
DeepSource will not raise this issue when the nested if
statements have comments in between them, as it could be explaining why the nested if
is in place.