Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pre-commit: add ruff hook #28

Closed
wants to merge 10 commits into from
Closed

pre-commit: add ruff hook #28

wants to merge 10 commits into from

Conversation

dtrifiro
Copy link
Collaborator

This PR adds ruff hook in the pre-commit configuration, as well as an initial ruff configuration in server/pyproject.toml.

Changed python files were formatted using the pre-commit hook (using ruff format).

@dtrifiro
Copy link
Collaborator Author

Just as a reference, here's a list of (unique) error messages/classes that we're currently getting (total error count is 1237).

We can probably disable quite a few of these either:

  • globally
  • on a by-file basis
  • on a by-line basis (add #noqa: <ERROR_CODE> pragmas)
Current ruff warnings/errors
  • A001 Variable compile is shadowing a Python builtin
  • ANN003 Missing type annotation for **deprecated_arguments
  • ANN102 Missing type annotation for cls in classmethod
  • ANN202 Missing return type annotation for private function add_batch
  • ANN205 Missing return type annotation for staticmethod compute_attention
  • ANN401 Dynamically typed expressions (typing.Any) are disallowed in model_config
  • ARG001 Unused function argument
  • ARG002 Unused method argument
  • ARG003 Unused class method argument
  • ARG004 Unused static method argument
  • ARG005 Unused lambda argument
  • B007 Loop control variable decoder_input_length not used within loop body
  • B017 pytest.raises(Exception) should be considered evil
  • B023 Function definition does not bind loop variable gptq
  • B024 BaseInferenceEngine is an abstract base class, but it has no abstract methods
  • B027 Batch.compact is an empty method in an abstract base class, but has no abstract decorator
  • B028 No explicit stacklevel keyword argument found
  • B904 Within an except clause, raise exceptions with raise ... from err or raise ... from None to distinguish them from errors in exception handling
  • BLE001 Do not catch blind exception
  • C403 Unnecessary list comprehension (rewrite as a set comprehension)
  • C405 Unnecessary list literal (rewrite as a set literal)
  • C414 Unnecessary list call within sorted()
  • C416 Unnecessary list comprehension (rewrite using list())
  • C419 Unnecessary list comprehension
  • C901 concatenate is too complex (16 > 10)
  • D200 One-line docstring should fit on one line
  • D205 1 blank line required between summary line and description
  • D400 First line should end with a period
  • D401 First line of docstring should be in imperative mood
  • D414 Section has no content ("Returns")
  • D415 First line should end with a period, question mark, or exclamation point
  • D417 Missing argument descriptions in the docstring for build_alibi_tensor
  • DTZ005 The use of datetime.datetime.now() without tz argument is not allowed
  • E712 Comparison to False should be cond is False or `if not cond
  • E721 Do not compare types, use isinstance()
  • E722 Do not use bare except
  • E731 Do not assign a lambda expression, use a def
  • E741 Ambiguous variable name
  • EM101 Exception must not use a string literal, assign to variable first
  • EM102 Exception must not use an f-string literal, assign to variable first
  • ERA001 Found commented-out code
  • F401 flash_attn.layers.rotary.RotaryEmbedding imported but unused; consider using importlib.util.find_spec to test for availability
  • F811 Redefinition of unused test_bloom from line 430
  • F821 Undefined name gptq
  • F841 Local variable max_positions is assigned to but never used
  • FBT001 Boolean-typed positional argument in function definition
  • FBT002 Boolean default positional argument in function definition
  • FBT003 Boolean positional value in function call
  • FIX002 Line contains TODO, consider resolving the issue
  • FIX003 Line contains XXX, consider resolving the issue
  • FIX004 Line contains HACK, consider resolving the issue
  • G004 Logging statement uses f-string
  • INP001 File custom_kernels/setup.py is part of an implicit namespace package. Add an __init__.py.
  • N802 Function name ClearCache should be lowercase
  • N803 Argument name X should be lowercase
  • N806 Variable Err1 in function should be lowercase
  • N806 Variable Y in function should be lowercase
  • N812 Lowercase functional imported as non-lowercase F
  • N818 Exception name PrefixNotFound should be named with an Error suffix
  • PD011 Use .to_numpy() instead of .values
  • PERF401 Use a list comprehension to create a transformed list
  • PGH003 Use specific rule codes when ignoring type issues
  • PLR0912 Too many branches (13 > 12)
  • PLR0913 Too many arguments in function definition (10 > 5)
  • PLR0915 Too many statements (51 > 50)
  • PLR1714 Consider merging multiple comparisons
  • PLW0602 Using global for ACT_ORDER but no assignment is done
  • PLW0603 Using the global statement to update ACT_ORDER is discouraged
  • PT011 pytest.raises(Exception) is too broad, set the match parameter or use a more specific exception
  • PT011 pytest.raises(ValueError) is too broad, set the match parameter or use a more specific exception
  • RET503 Missing explicit return at the end of function able to return non-None value
  • RET504 Unnecessary assignment to alibi before return statement
  • RET505 Unnecessary elif after return statement
  • RET508 Unnecessary else after break statement
  • RUF005 Consider (*all_attentions, layer_outputs[3]) instead of concatenation
  • RUF012 Mutable class attributes should be annotated with typing.ClassVar
  • RUF013 PEP 484 prohibits implicit Optional
  • S108 Probable insecure usage of temporary file or directory
  • S110 try-except-pass detected, consider logging the exception
  • S311 Standard pseudo-random generators are not suitable for cryptographic purposes
  • SIM102 Use a single if statement instead of nested if statements
  • SIM118 Use key in dict instead of key in dict.keys()
  • SLF001 Private member accessed
  • TD001 Invalid TODO tag
  • TD002 Missing author in TODO; try
  • TD003 Missing issue link on the line following this TODO
  • TD004 Missing colon in TODO
  • TD005 Missing issue description after TODO
  • TRY002 Create your own exception
  • TRY003 Avoid specifying long messages outside the exception class
  • TRY201 Use raise without specifying exception name
  • TRY300 Consider moving this statement to an else block
  • TRY301 Abstract raise to an inner function
  • UP008 Use super() instead of super(__class__, self)

@dtrifiro dtrifiro mentioned this pull request Feb 15, 2024
Signed-off-by: Daniele Trifirò <[email protected]>
Signed-off-by: Daniele Trifirò <[email protected]>
Signed-off-by: Daniele Trifirò <[email protected]>
Signed-off-by: Daniele Trifirò <[email protected]>
Signed-off-by: Daniele Trifirò <[email protected]>
Signed-off-by: Daniele Trifirò <[email protected]>
Signed-off-by: Daniele Trifirò <[email protected]>
Signed-off-by: Daniele Trifirò <[email protected]>
@dtrifiro
Copy link
Collaborator Author

dtrifiro commented Mar 4, 2024

@joerunde we can take a look at this after #26 has been merged. We mostly need to decide what rules we're interested in and which ones we can suppress

@dtrifiro dtrifiro closed this Apr 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant