ayon-core icon indicating copy to clipboard operation
ayon-core copied to clipboard

Ruff settings

Open antirotor opened this issue 4 months ago • 8 comments

Problem

Current ruff settings are to prohibitive.

We can reverse the logic, select all rules and just ignore those that we must. Here is the list of rules I had to disable in 3dequalizer addon for some reasons I'll try to explain here:

  • D203 - one-blank-line-before-class: exclusive with D211[^1]
  • D213 - multi-line-summary-second-line, exclusive with D212[^1]
  • D406 - new-line-after-section-name [^1]
  • D407 - dashed-underline-after-section [^1]
  • PTH - this is ignoring all "use pathlib" warnings. We have a lot of os.path logic all over the place and rewriting it all to make use of pathlib would be major work.
  • ANN101 - this is deprecated check where self should be type annotated for the sake of older IDE that couldn't infer the type.
  • ANN102 - the same thing as ⬆️ but for cls
  • ANN204 - return type annotation for special methods. This requires even __init__() to have that[^2]
  • COM812 - missing-trailing-comma - while this rule make sense, it is enforcing trailing commas even within function arguments if multiline.
  • S603 - subprocess-without-shell-equals-true. Requires validation of input arguments, but it is vague how to achieve it?
  • ERA001 - commented-out-code - code that is commented out is IMO still valuable as illustration or example.
  • TRY003 - raise-vanilla-args - define new exception if message is too long. This just adds more code that needs to be maintained.
  • UP007 - non-pep604-annotation - since we need to support python 3.7, we can't use | in type annotations.
  • ARG002 - unused-method-argument - for method that are overriden, even unused arguments should be listed for clarity, no?
  • INP001 - implicit-namespace-package - this rule is forcing __init__.py to be almost in all directories with any python files even in a case where nothing will ever be imported from there. for docstrings ("D" rules) we should add pydocstyle.convention = "google"
  • UP006 - non-pep585-annotation - this is for compatibility with py37 - List[int] = [1, 2, 3] vs. list[int] = [1, 2, 3]
  • UP007 - non-pep604-annotation - this is for compatibility with py37 - foo: Union[int, str] = 1 vs. foo: int | str = 1
  • UP035 - deprecated-import - py37 compatibility too, when you need to import something from deprecated location

[^1]: This should be solved by pydocstyle.convention = "google" so no need to ignore [^2]: Unless mypy-init-return is used in ruff config.

Some notes:

  • Most of the error are due to the docstrings - like missing package level docstring, etc. D100, D104, D107
  • printf style formatting: there are some collisions with how we use printf style in logging. We shouldn't basically. We should make use extra argument in logging:
# wrong
self.log.info(f"this is {error}")

# also wrong
self.log.info("this is %s" % error)

# also wrong
self.log.info("this is {}".format(error))

# this is right
self.log.info("this is %s, error)

antirotor avatar Oct 01 '24 12:10 antirotor