diff --git a/.pylintrc b/.pylintrc index 7dc311f..546127b 100644 --- a/.pylintrc +++ b/.pylintrc @@ -34,15 +34,6 @@ unsafe-load-any-extension=no # run arbitrary code extension-pkg-whitelist=lxml -# Allow optimization of some AST trees. This will activate a peephole AST -# optimizer, which will apply various small optimizations. For instance, it can -# be used to obtain the result of joining multiple strings with the addition -# operator. Joining a lot of strings can lead to a maximum recursion error in -# Pylint and this flag can prevent that. It has one side effect, the resulting -# AST will be different than the one from reality. This option is deprecated -# and it will be removed in Pylint 2.0. -optimize-ast=no - [MESSAGES CONTROL] @@ -65,7 +56,13 @@ confidence= # --enable=similarities". If you want to run only the classes checker, but have # no Warning level messages displayed, use"--disable=all --enable=classes # --disable=W" -disable=locally-disabled, super-with-arguments, raise-missing-from +disable=locally-disabled, super-with-arguments, raise-missing-from, + consider-using-f-string, + use-dict-literal, + use-list-literal, + global-variable-not-assigned, + unrecognized-option, + useless-option-value [REPORTS] @@ -75,12 +72,6 @@ disable=locally-disabled, super-with-arguments, raise-missing-from # mypackage.mymodule.MyReporterClass. output-format=text -# Put messages in a separate file for each module / package specified on the -# command line instead of printing them on stdout. Reports (if any) will be -# written in a file name "pylint_global.[txt|html]". This option is deprecated -# and it will be removed in Pylint 2.0. -files-output=no - # Tells whether to display a full report or only the messages reports=no @@ -118,63 +109,33 @@ property-classes=abc.abstractproperty # Regular expression matching correct function names function-rgx=[a-z_][a-z0-9_]{2,30}$ -# Naming hint for function names -function-name-hint=[a-z_][a-z0-9_]{2,30}$ - # Regular expression matching correct variable names variable-rgx=[a-z_][a-z0-9_]{2,30}$ -# Naming hint for variable names -variable-name-hint=[a-z_][a-z0-9_]{2,30}$ - # Regular expression matching correct constant names const-rgx=(([A-Z_][A-Z0-9_]*)|(__.*__))$ -# Naming hint for constant names -const-name-hint=(([A-Z_][A-Z0-9_]*)|(__.*__))$ - # Regular expression matching correct attribute names attr-rgx=[a-z_][a-z0-9_]{2,30}$ -# Naming hint for attribute names -attr-name-hint=[a-z_][a-z0-9_]{2,30}$ - # Regular expression matching correct argument names argument-rgx=[a-z_][a-z0-9_]{2,30}$ -# Naming hint for argument names -argument-name-hint=[a-z_][a-z0-9_]{2,30}$ - # Regular expression matching correct class attribute names class-attribute-rgx=([A-Za-z_][A-Za-z0-9_]{2,30}|(__.*__))$ -# Naming hint for class attribute names -class-attribute-name-hint=([A-Za-z_][A-Za-z0-9_]{2,30}|(__.*__))$ - # Regular expression matching correct inline iteration names inlinevar-rgx=[A-Za-z_][A-Za-z0-9_]*$ -# Naming hint for inline iteration names -inlinevar-name-hint=[A-Za-z_][A-Za-z0-9_]*$ - # Regular expression matching correct class names class-rgx=[A-Z_][a-zA-Z0-9]+$ -# Naming hint for class names -class-name-hint=[A-Z_][a-zA-Z0-9]+$ - # Regular expression matching correct module names module-rgx=(([a-z_][a-z0-9_-]*)|([A-Z][a-zA-Z0-9]+))$ -# Naming hint for module names -module-name-hint=(([a-z_][a-z0-9_]*)|([A-Z][a-zA-Z0-9]+))$ - # Regular expression matching correct method names method-rgx=[a-z_][a-z0-9_]{2,42}$ -# Naming hint for method names -method-name-hint=[a-z_][a-z0-9_]{2,42}$ - # Regular expression which should only match function or class names that do # not require a docstring. no-docstring-rgx=^_ @@ -202,12 +163,6 @@ ignore-long-lines=^\s*(# )??$ # else. single-line-if-stmt=no -# List of optional constructs for which whitespace checking is disabled. `dict- -# separator` is used to allow tabulation in dicts, etc.: {1 : 1,\n222: 2}. -# `trailing-comma` allows a space between comma and closing bracket: (a, ). -# `empty-line` allows space-only lines. -no-space-check=trailing-comma,dict-separator - # Maximum number of lines in a module max-module-lines=1000 diff --git a/dev-requirements.txt b/dev-requirements.txt index fee63f9..f40feda 100644 --- a/dev-requirements.txt +++ b/dev-requirements.txt @@ -6,7 +6,7 @@ httpx>=0.23.0 respx>=0.19.2 setuptools>=38.2.4 setuptools-scm>=1.15.6 -pylint==2.8.3 +pylint==2.15.0 pytest-cov>=3.0.0 flake8==3.8.4 bandit==1.7.5 diff --git a/pyodata/v2/model.py b/pyodata/v2/model.py index 9d6b912..7c53df0 100644 --- a/pyodata/v2/model.py +++ b/pyodata/v2/model.py @@ -282,7 +282,6 @@ class EdmStructTypeSerializer: @staticmethod def to_literal(edm_type, value): - # pylint: disable=no-self-use if not edm_type: raise PyODataException(f'Cannot encode value {value} without complex type information') @@ -296,7 +295,6 @@ def to_literal(edm_type, value): @staticmethod def from_json(edm_type, value): - # pylint: disable=no-self-use if not edm_type: raise PyODataException(f'Cannot decode value {value} without complex type information') @@ -310,7 +308,6 @@ def from_json(edm_type, value): @staticmethod def from_literal(edm_type, value): - # pylint: disable=no-self-use if not edm_type: raise PyODataException(f'Cannot decode value {value} without complex type information') @@ -328,11 +325,9 @@ class TypTraits: def __repr__(self): return self.__class__.__name__ - # pylint: disable=no-self-use def to_literal(self, value): return value - # pylint: disable=no-self-use def from_json(self, value): return value @@ -568,11 +563,9 @@ def from_literal(self, value): class EdmStringTypTraits(TypTraits): """Edm.String traits""" - # pylint: disable=no-self-use def to_literal(self, value): return '\'%s\'' % (str(value).replace("'", "''")) - # pylint: disable=no-self-use def from_json(self, value): return value @@ -585,11 +578,9 @@ def from_literal(self, value): class EdmBooleanTypTraits(TypTraits): """Edm.Boolean traits""" - # pylint: disable=no-self-use def to_literal(self, value): return 'true' if value else 'false' - # pylint: disable=no-self-use def from_json(self, value): return value @@ -600,11 +591,9 @@ def from_literal(self, value): class EdmIntTypTraits(TypTraits): """All Edm Integer traits""" - # pylint: disable=no-self-use def to_literal(self, value): return '%d' % (value) - # pylint: disable=no-self-use def from_json(self, value): return int(value) @@ -615,11 +604,9 @@ def from_literal(self, value): class EdmLongIntTypTraits(TypTraits): """All Edm Integer for big numbers traits""" - # pylint: disable=no-self-use def to_literal(self, value): return '%dL' % (value) - # pylint: disable=no-self-use def from_json(self, value): if value[-1] == 'L': return int(value[:-1]) @@ -655,14 +642,12 @@ def edm_double(): def edm_single(): return EdmFPNumTypTraits(7, 'f', '{:f}') - # pylint: disable=no-self-use def to_literal(self, value): return self.conversion.format(value) def to_json(self, value): return self.to_literal(value) - # pylint: disable=no-self-use def from_json(self, value): if not isinstance(value, str) or value[-1] != self.suffix: return float(value) @@ -680,11 +665,9 @@ def __init__(self, edm_type=None): super().__init__() self._edm_type = edm_type - # pylint: disable=no-self-use def to_literal(self, value): return EdmStructTypeSerializer.to_literal(self._edm_type, value) - # pylint: disable=no-self-use def from_json(self, value): return EdmStructTypeSerializer.from_json(self._edm_type, value) @@ -761,14 +744,12 @@ def item_type(self): def traits(self): return self - # pylint: disable=no-self-use def to_literal(self, value): if not isinstance(value, list): raise PyODataException(f'Bad format: invalid list value {value}') return [self._item_type.traits.to_literal(v) for v in value] - # pylint: disable=no-self-use def from_json(self, value): if not isinstance(value, list): raise PyODataException(f'Bad format: invalid list value {value}') diff --git a/pyodata/v2/service.py b/pyodata/v2/service.py index 05449d4..ec58e20 100644 --- a/pyodata/v2/service.py +++ b/pyodata/v2/service.py @@ -250,27 +250,22 @@ def handler(self): def get_path(self): """Get path of the HTTP request""" - # pylint: disable=no-self-use return '' def get_query_params(self): """Get query params""" - # pylint: disable=no-self-use return dict(self._customs) def get_method(self): """Get HTTP method""" - # pylint: disable=no-self-use return 'GET' def get_body(self): """Get HTTP body or None if not applicable""" - # pylint: disable=no-self-use return None def get_default_headers(self): """Get dict of Child specific HTTP headers""" - # pylint: disable=no-self-use return dict() def get_headers(self): @@ -500,7 +495,6 @@ def get_path(self): return self._last_segment def get_method(self): - # pylint: disable=no-self-use return 'POST' def _get_body(self): @@ -583,7 +577,6 @@ def get_encode_path(self): return self._encode_path def get_method(self): - # pylint: disable=no-self-use return 'DELETE' @@ -624,11 +617,9 @@ def get_path(self): return self._entity_set.name + self._entity_key.to_key_string() def get_method(self): - # pylint: disable=no-self-use return self._method def get_body(self): - # pylint: disable=no-self-use body = {} for key, val in self._values.items(): body[key] = val @@ -1281,62 +1272,48 @@ def _decode_expression(self, expr, val): return expression - # pylint: disable=no-self-use def _combine_expressions(self, expressions): return ' and '.join(expressions) - # pylint: disable=too-many-return-statements, too-many-branches + # pylint: disable=too-many-return-statements def _build_expression(self, field_name, operator, value): target_field = self.proprty_obj(field_name) if operator not in ['length', 'in', 'range']: value = target_field.to_literal(value) - if operator == 'lt': - return f'{field_name} lt {value}' - - if operator == 'lte': - return f'{field_name} le {value}' - - if operator == 'gte': - return f'{field_name} ge {value}' - - if operator == 'gt': - return f'{field_name} gt {value}' - - if operator == 'startswith': - return f'startswith({field_name}, {value}) eq true' - - if operator == 'endswith': - return f'endswith({field_name}, {value}) eq true' - - if operator == 'length': - value = int(value) - return f'length({field_name}) eq {value}' - - if operator in ['contains']: - return f'substringof({value}, {field_name}) eq true' - - if operator == 'range': - if not isinstance(value, tuple | list): - raise TypeError(f'Range must be tuple or list not {type(value)}') - - if len(value) != 2: - raise ValueError('Only two items can be passed in a range.') - - low_bound = target_field.to_literal(value[0]) - high_bound = target_field.to_literal(value[1]) - - return f'{field_name} gte {low_bound} and {field_name} lte {high_bound}' - - if operator == 'in': - literal_values = (f'{field_name} eq {target_field.to_literal(item)}' for item in value) - return ' or '.join(literal_values) - - if operator == 'eq': - return f'{field_name} eq {value}' - - raise ValueError(f'Invalid expression {operator}') + match operator: + case 'lt': + return f'{field_name} lt {value}' + case 'lte': + return f'{field_name} le {value}' + case 'gte': + return f'{field_name} ge {value}' + case 'gt': + return f'{field_name} gt {value}' + case 'startswith': + return f'startswith({field_name}, {value}) eq true' + case 'endswith': + return f'endswith({field_name}, {value}) eq true' + case 'length': + return f'length({field_name}) eq {int(value)}' + case 'contains': + return f'substringof({value}, {field_name}) eq true' + case 'range': + if not isinstance(value, tuple | list): + raise TypeError(f'Range must be tuple or list not {type(value)}') + if len(value) != 2: + raise ValueError('Only two items can be passed in a range.') + low_bound = target_field.to_literal(value[0]) + high_bound = target_field.to_literal(value[1]) + return f'{field_name} gte {low_bound} and {field_name} lte {high_bound}' + case 'in': + literal_values = (f'{field_name} eq {target_field.to_literal(item)}' for item in value) + return ' or '.join(literal_values) + case 'eq': + return f'{field_name} eq {value}' + case _: + raise ValueError(f'Invalid expression {operator}') def __str__(self): expressions = self._process_expressions() @@ -1939,7 +1916,6 @@ def get_boundary(self): return self.id def get_default_headers(self): - # pylint: disable=no-self-use return {'Content-Type': f'multipart/mixed;boundary={self.get_boundary()}'} def get_body(self): @@ -1974,11 +1950,9 @@ def get_boundary(self): return 'batch_' + self.id def get_path(self): - # pylint: disable=no-self-use return '$batch' def get_method(self): - # pylint: disable=no-self-use return 'POST'