Skip to content

Commit

Permalink
πŸ”§β™»οΈ Remove parameter.py from linter exceptions (#862)
Browse files Browse the repository at this point in the history
* πŸ”§πŸ‘Œ Move up yesqa hook, to remove noqa's before linting

* πŸ”§β™»οΈ Moved pydocstyle config to tox.ini

* πŸ”§ ♻️ Moved up flake8 hook directly after yesqa hook

* πŸ”§β¬†οΈ Updated pre-commit config

* πŸ”§β™»οΈ Run Doc linting tools via flake8

This allows a uniform usage of 'noqa's, which is also compatible with yesqa

* πŸ”§πŸ©Ή Remove parameter.py from linter exceptions

* πŸ”§ Fixed darglint version to 1.8.0 due to bug in 1.8.1

Ref: terrencepreilly/darglint#180
  • Loading branch information
s-weigand authored Oct 22, 2021
1 parent a1b44c5 commit 92cbb57
Show file tree
Hide file tree
Showing 6 changed files with 118 additions and 121 deletions.
70 changes: 32 additions & 38 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ repos:
args: [--remove]

- repo: https://github.com/asottile/pyupgrade
rev: v2.19.4
rev: v2.29.0
hooks:
- id: pyupgrade
types: [file]
Expand All @@ -32,35 +32,35 @@ repos:
types_or: [python, pyi]

- repo: https://github.com/psf/black
rev: 21.6b0
rev: 21.9b0
hooks:
- id: black
types: [file]
types_or: [python, pyi]
language_version: python3

- repo: https://github.com/PyCQA/isort
rev: 5.9.1
rev: 5.9.3
hooks:
- id: isort
types: [file]
types_or: [python, pyi]
minimum_pre_commit_version: 2.9.0

- repo: https://github.com/asottile/setup-cfg-fmt
rev: v1.17.0
rev: v1.18.0
hooks:
- id: setup-cfg-fmt

# Notebook tools
- repo: https://github.com/kynan/nbstripout
rev: 0.4.0
rev: 0.5.0
hooks:
- id: nbstripout
args: [--strip-empty-cells]

- repo: https://github.com/nbQA-dev/nbQA
rev: 0.13.1
rev: 1.1.1
hooks:
- id: nbqa-black
additional_dependencies: [black==21.6b0]
Expand All @@ -75,57 +75,51 @@ repos:
args: [--nbqa-mutate]

# Linters
- repo: https://github.com/asottile/yesqa
rev: v1.2.3
hooks:
- id: yesqa
types: [file]
types_or: [python, pyi]
additional_dependencies: [flake8-docstrings, flake8-print]

- repo: https://github.com/PyCQA/pydocstyle
rev: 6.1.1
- repo: https://github.com/PyCQA/flake8
rev: 4.0.1
hooks:
- id: pydocstyle
files: "^glotaran/(plugin_system|utils|deprecation|testing|parameter|project)"
exclude: "docs|tests?/"
# this is needed due to the following issue:
# https://github.com/PyCQA/pydocstyle/issues/368
args: [--ignore-decorators=wrap_func_as_method]
- id: flake8
name: "flake8 lint code"
types: [file]
types_or: [python, pyi]
additional_dependencies:
[flake8-pyi, flake8-comprehensions, flake8-print]

- repo: https://github.com/terrencepreilly/darglint
rev: v1.8.0
- repo: https://github.com/PyCQA/flake8
rev: 4.0.1
hooks:
- id: darglint
- id: flake8
alias: flake8-docs
args:
- "--select=D,DAR"
name: "flake8 lint docstrings"
files: "^glotaran/(plugin_system|utils|deprecation|testing|parameter|project)"
exclude: "docs|tests?/"
additional_dependencies: [flake8-docstrings, darglint==1.8.0]

- repo: https://github.com/pre-commit/mirrors-mypy
rev: v0.910
rev: v0.910-1
hooks:
- id: mypy
files: "^glotaran/(plugin_system|utils|deprecation|testing|parameter|project)"
exclude: "docs"
additional_dependencies: [types-all]

- repo: https://github.com/econchick/interrogate
rev: 1.4.0
rev: 1.5.0
hooks:
- id: interrogate
args: [-vv, --config=pyproject.toml, glotaran]
pass_filenames: false

- repo: https://github.com/asottile/yesqa
rev: v1.2.3
hooks:
- id: yesqa
types: [file]
types_or: [python, pyi]
additional_dependencies: [flake8-docstrings, flake8-print]
exclude: "parameter.py"

- repo: https://github.com/PyCQA/flake8
rev: 3.9.2
hooks:
- id: flake8
types: [file]
types_or: [python, pyi]
additional_dependencies:
[flake8-pyi, flake8-comprehensions, flake8-print]

- repo: https://github.com/myint/rstcheck
rev: "3f92957478422df87bd730abde66f089cc1ee19b"
hooks:
Expand All @@ -137,7 +131,7 @@ repos:
hooks:
- id: rst-backticks
- id: python-check-blanket-noqa
exclude: "parameter.py|docs|tests?"
exclude: "docs|tests?"
- id: python-check-blanket-type-ignore
exclude: "docs|tests?"
- id: python-use-type-annotations
Expand Down
130 changes: 64 additions & 66 deletions glotaran/parameter/parameter.py
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,6 @@ def transformed_expression(self) -> str | None:
-------
str | None
The transformed expression.
"""
if self.expression is not None and self._transformed_expression is None:
self._transformed_expression = PARAMETER_EXPRESION_REGEX.sub(
Expand All @@ -343,15 +342,14 @@ def transformed_expression(self) -> str | None:
return self._transformed_expression

@property
def standard_error(self) -> float: # noqa D401
def standard_error(self) -> float:
"""Standard error of the optimized parameter.
Returns
-------
float
The standard error of the parameter.
"""

""" # noqa: D401
return self._stderr

@standard_error.setter
Expand Down Expand Up @@ -411,7 +409,7 @@ def set_value_from_optimization(self, value: float):
"""
self.value = np.exp(value) if self.non_negative else value

def __getstate__(self): # noqa D400
def __getstate__(self):
"""Get state for pickle."""
return (
self.label,
Expand All @@ -425,7 +423,7 @@ def __getstate__(self): # noqa D400
self.vary,
)

def __setstate__(self, state): # noqa D400
def __setstate__(self, state):
"""Set state from pickle."""
(
self.label,
Expand All @@ -439,135 +437,135 @@ def __setstate__(self, state): # noqa D400
self.vary,
) = state

def __repr__(self): # noqa D400
def __repr__(self):
"""Representation used by repl and tracebacks."""
return (
f"{type(self).__name__}(label={self.label!r}, value={self.value!r},"
f" expression={self.expression!r}, vary={self.vary!r})"
)

def __array__(self): # noqa D400
"""array"""
def __array__(self):
"""array""" # noqa: D400, D403
return np.array(float(self._value), dtype=float)

def __str__(self) -> str: # noqa D400
def __str__(self) -> str:
"""Representation used by print and str."""
return (
f"__{self.label}__: _Value_: {self.value}, _StdErr_: {self.standard_error}, _Min_:"
f" {self.minimum}, _Max_: {self.maximum}, _Vary_: {self.vary},"
f" _Non-Negative_: {self.non_negative}, _Expr_: {self.expression}"
)

def __abs__(self): # noqa D400
"""abs"""
def __abs__(self):
"""abs""" # noqa: D400, D403
return abs(self._value)

def __neg__(self): # noqa D400
"""neg"""
def __neg__(self):
"""neg""" # noqa: D400, D403
return -self._value

def __pos__(self): # noqa D400
"""positive"""
def __pos__(self):
"""positive""" # noqa: D400, D403
return +self._value

def __int__(self): # noqa D400
"""int"""
def __int__(self):
"""int""" # noqa: D400, D403
return int(self._value)

def __float__(self): # noqa D400
"""float"""
def __float__(self):
"""float""" # noqa: D400, D403
return float(self._value)

def __trunc__(self): # noqa D400
"""trunc"""
def __trunc__(self):
"""trunc""" # noqa: D400, D403
return self._value.__trunc__()

def __add__(self, other): # noqa D400
"""+"""
def __add__(self, other):
"""+""" # noqa: D400
return self._value + other

def __sub__(self, other): # noqa D400
"""-"""
def __sub__(self, other):
"""-""" # noqa: D400
return self._value - other

def __truediv__(self, other): # noqa D400
"""/"""
def __truediv__(self, other):
"""/""" # noqa: D400
return self._value / other

def __floordiv__(self, other): # noqa D400
"""//"""
def __floordiv__(self, other):
"""//""" # noqa: D400
return self._value // other

def __divmod__(self, other): # noqa D400
"""divmod"""
def __divmod__(self, other):
"""divmod""" # noqa: D400, D403
return divmod(self._value, other)

def __mod__(self, other): # noqa D400
"""%"""
def __mod__(self, other):
"""%""" # noqa: D400
return self._value % other

def __mul__(self, other): # noqa D400
"""*"""
def __mul__(self, other):
"""*""" # noqa: D400
return self._value * other

def __pow__(self, other): # noqa D400
"""**"""
def __pow__(self, other):
"""**""" # noqa: D400
return self._value ** other

def __gt__(self, other): # noqa D400
""">"""
def __gt__(self, other):
""">""" # noqa: D400
return self._value > other

def __ge__(self, other): # noqa D400
""">="""
def __ge__(self, other):
""">=""" # noqa: D400
return self._value >= other

def __le__(self, other): # noqa D400
"""<="""
def __le__(self, other):
"""<=""" # noqa: D400
return self._value <= other

def __lt__(self, other): # noqa D400
"""<"""
def __lt__(self, other):
"""<""" # noqa: D400
return self._value < other

def __eq__(self, other): # noqa D400
"""=="""
def __eq__(self, other):
"""==""" # noqa: D400
return self._value == other

def __ne__(self, other): # noqa D400
"""!="""
def __ne__(self, other):
"""!=""" # noqa: D400
return self._value != other

def __radd__(self, other): # noqa D400
"""+ (right)"""
def __radd__(self, other):
"""+ (right)""" # noqa: D400
return other + self._value

def __rtruediv__(self, other): # noqa D400
"""/ (right)"""
def __rtruediv__(self, other):
"""/ (right)""" # noqa: D400
return other / self._value

def __rdivmod__(self, other): # noqa D400
"""divmod (right)"""
def __rdivmod__(self, other):
"""divmod (right)""" # noqa: D400, D403
return divmod(other, self._value)

def __rfloordiv__(self, other): # noqa D400
"""// (right)"""
def __rfloordiv__(self, other):
"""// (right)""" # noqa: D400
return other // self._value

def __rmod__(self, other): # noqa D400
"""% (right)"""
def __rmod__(self, other):
"""% (right)""" # noqa: D400
return other % self._value

def __rmul__(self, other): # noqa D400
"""* (right)"""
def __rmul__(self, other):
"""* (right)""" # noqa: D400
return other * self._value

def __rpow__(self, other): # noqa D400
"""** (right)"""
def __rpow__(self, other):
"""** (right)""" # noqa: D400
return other ** self._value

def __rsub__(self, other): # noqa D400
"""- (right)"""
def __rsub__(self, other):
"""- (right)""" # noqa: D400
return other - self._value


Expand Down
Loading

0 comments on commit 92cbb57

Please sign in to comment.