Skip to content

Commit

Permalink
Use dataclasses and enums instead of list of ints
Browse files Browse the repository at this point in the history
  • Loading branch information
JanEricNitschke committed Sep 7, 2024
1 parent 9c35f2d commit 0fd694b
Show file tree
Hide file tree
Showing 7 changed files with 816 additions and 459 deletions.
2 changes: 2 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ repos:
args: [
"-rn", # Only display messages
"-sn", # Don't display the score
"--rcfile",
"tictactoe_python/pyproject.toml",
]

# golang specific
Expand Down
120 changes: 119 additions & 1 deletion tictactoe_python/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,27 @@ target-version = "py311"
[tool.ruff.lint]
# Enable pycodestyle (`E`) and Pyflakes (`F`) codes by default.
select = ["ALL"]
ignore = ["ANN101", "S311", "T20", "COM812", "ISC001"]
ignore = [
# Conflict with formatter
"W191",
"E111",
"E114",
"E117",
"D206",
"D300",
"Q000",
"Q001",
"Q003",
"COM812",
"COM819",
"ISC001",
"ISC002",
# Others
"ANN101",
"S311",
"T20",
"E501",
]
# Allow unused variables when underscore-prefixed.
dummy-variable-rgx = "^(_+|(_+[a-zA-Z0-9_]*[a-zA-Z0-9]+?))$"

Expand Down Expand Up @@ -79,3 +99,101 @@ reportAssertAlwaysTrue = "error"
reportUnnecessaryTypeIgnoreComment = "error"
reportImplicitOverride = "error"
reportShadowedImports = "error"

[tool.pylint.main]
# Specify a score threshold under which the program will exit with error.
fail-under = 10.0

[tool.pylint.basic]
# Good variable names which should always be accepted, separated by a comma.
good-names = ["i", "j", "k", "ex", "Run", "_", "x", "y", "z", "e", "ok"]
include-naming-hint = true
typevar-rgx = "^_{0,2}(?!T[A-Z])([A-Z]|T[0-9]?)(?:[A-Z]*[0-9]*)?(?:_co(?:ntra)?)?$"

[tool.pylint.design]
# Maximum number of arguments for function / method.
max-args = 10

# Maximum number of attributes for a class (see R0902).
# Should be lowered to 7 but got no time for that atm
max-attributes = 15

# Maximum number of boolean expressions in an if statement (see R0916).
max-bool-expr = 5

# Maximum number of branch for function / method body.
# Same as for max-attributes
max-branches = 12

# Maximum number of locals for function / method body.
# Same as for max-attributes
max-locals = 15

# Maximum number of public methods for a class (see R0904).
max-public-methods = 20

# Maximum number of return / yield for function / method body.
max-returns = 6

# Maximum number of statements in function / method body.
max-statements = 60

# Minimum number of public methods for a class (see R0903).
# Same as for max-attributes
min-public-methods = 2

[tool.pylint.exceptions]
# Exceptions that will emit a warning when caught.
overgeneral-exceptions = ["builtins.BaseException"]

[tool.pylint.format]
# Maximum number of characters on a single line.
max-line-length = 120

# Maximum number of lines in a module.
max-module-lines = 2000

[tool.pylint."messages control"]
# Only show warnings with the listed confidence levels. Leave empty to show all.
# Valid levels: HIGH, CONTROL_FLOW, INFERENCE, INFERENCE_FAILURE, UNDEFINED.
confidence = ["HIGH", "CONTROL_FLOW", "INFERENCE", "INFERENCE_FAILURE", "UNDEFINED"]

# Disable the message, report, category or checker with the given id(s). You can
# either give multiple identifiers separated by comma (,) or put this option
# multiple times (only on the command line, not in the configuration file where
# it should appear only once). You can also use "--disable=all" to disable
# everything first and then re-enable specific checks. For example, if you want
# to run only the similarities checker, you can use "--disable=all
# --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 = ["unnecessary-ellipsis"] # but needed for pyright

[tool.pylint.miscellaneous]
# List of note tags to take in consideration, separated by a comma.
notes = ["FIXME", "XXX", "TODO"]

[tool.pylint.refactoring]
# Maximum number of nested blocks for function / method body
max-nested-blocks = 5

# Complete name of functions that never returns. When checking for inconsistent-
# return-statements if a never returning function is called then it will be
# considered as an explicit return statement and no message will be printed.
never-returning-functions = ["sys.exit", "argparse.parse_error"]

[tool.pylint.reports]
# Python expression which should return a score less than or equal to 10. You
# have access to the variables 'fatal', 'error', 'warning', 'refactor',
# 'convention', and 'info' which contain the number of messages in each category,
# as well as 'statement' which is the total number of statements analyzed. This
# score is used by the global evaluation report (RP0004).
evaluation = "max(0, 0 if fatal else 10.0 - ((float(5 * error + warning + refactor + convention) / statement) * 10))"

[tool.pylint.similarities]
# Minimum lines number of a similarity.
min-similarity-lines = 20

[tool.pylint.spelling]
# Limits count of emitted suggestions for spelling mistakes.
max-spelling-suggestions = 4
1 change: 1 addition & 0 deletions tictactoe_python/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
typing-extensions<=4.4.0
15 changes: 15 additions & 0 deletions tictactoe_python/tests/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
"""Fixtures for tictactoe tests."""

import pytest

from tictactoe.tictactoe_python import TicTacToe


@pytest.fixture
def tictactoe() -> TicTacToe:
"""Return a TicTacToe instance.
Returns:
TicTacToe: Return a freashly created TicTacToe instance.
"""
return TicTacToe()
2 changes: 1 addition & 1 deletion tictactoe_python/tests/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
pre-commit==3.8.0
pylint==3.2.7
pyright==1.1.378
pyright==1.1.379
pytest==8.3.2
pytest-cov==5.0.0
Loading

0 comments on commit 0fd694b

Please sign in to comment.