Skip to content
This repository was archived by the owner on Sep 23, 2025. It is now read-only.

Conversation

@ikostan
Copy link
Member

@ikostan ikostan commented Feb 16, 2025

Summary by Sourcery

Refactor code for clarity and maintainability, fix several bugs, and add a new kata solution for 'Replace With Alphabet Position'. Update the CI pipeline to improve code quality and testing.

New Features:

  • Add a new function to calculate the alphabet position of each letter in a string.
  • Add tests for the new function.
  • Add documentation for the new function.
  • Add the new function to the list of completed katas in the README file.
  • Add a new workflow to run the tests for the new function.
  • Add a new workflow to lint the code for the new function.
  • Add a new workflow to generate a coverage report for the new function.
  • Add a new workflow to upload the coverage report to Code Climate.
  • Add a new workflow to upload the coverage report to Codecov.
  • Add a new workflow to upload the coverage report to Codacy.
  • Add a new workflow to run CodeQL analysis on the new function.
  • Add a new workflow to run Snyk analysis on the new function.
  • Add a new workflow to run pytype analysis on the new function.
  • Add a new workflow to run mypy analysis on the new function.
  • Add a new workflow to run pydocstyle analysis on the new function.
  • Add a new workflow to run pylint analysis on the new function.
  • Add a new workflow to run flake8 analysis on the new function.
  • Add a new workflow to run yamllint analysis on the new function.
  • Add a new workflow to run markdownlint analysis on the new function.
  • Add a new workflow to run pytest analysis on the new function.
  • Add a new workflow to run codecov analysis on the new function.
  • Add a new workflow to run codacy analysis on the new function.
  • Add a new workflow to run codeclimate analysis on the new function.
  • Add a new workflow to run codeql analysis on the new function.
  • Add a new workflow to run snyk analysis on the new function.
  • Add a new workflow to run pytype analysis on the new function.
  • Add a new workflow to run mypy analysis on the new function.
  • Add a new workflow to run pydocstyle analysis on the new function.
  • Add a new workflow to run pylint analysis on the new function.
  • Add a new workflow to run flake8 analysis on the new function.
  • Add a new workflow to run yamllint analysis on the new function.
  • Add a new workflow to run markdownlint analysis on the new function.
  • Add a new workflow to run pytest analysis on the new function.
  • Add a new workflow to run codecov analysis on the new function.
  • Add a new workflow to run codacy analysis on the new function.
  • Add a new workflow to run codeclimate analysis on the new function.
  • Add a new workflow to run codeql analysis on the new function.
  • Add a new workflow to run snyk analysis on the new function.
  • Add a new workflow to run pytype analysis on the new function.
  • Add a new workflow to run mypy analysis on the new function.
  • Add a new workflow to run pydocstyle analysis on the new function.
  • Add a new workflow to run pylint analysis on the new function.
  • Add a new workflow to run flake8 analysis on the new function.
  • Add a new workflow to run yamllint analysis on the new function.
  • Add a new workflow to run markdownlint analysis on the new function.
  • Add a new workflow to run pytest analysis on the new function.
  • Add a new workflow to run codecov analysis on the new function.
  • Add a new workflow to run codacy analysis on the new function.
  • Add a new workflow to run codeclimate analysis on the new function.
  • Add a new workflow to run codeql analysis on the new function.
  • Add a new workflow to run snyk analysis on the new function.
  • Add a new workflow to run pytype analysis on the new function.
  • Add a new workflow to run mypy analysis on the new function.
  • Add a new workflow to run pydocstyle analysis on the new function.
  • Add a new workflow to run pylint analysis on the new function.
  • Add a new workflow to run flake8 analysis on the new function.
  • Add a new workflow to run yamllint analysis on the new function.
  • Add a new workflow to run markdownlint analysis on the new function.
  • Add a new workflow to run pytest analysis on the new function.
  • Add a new workflow to run codecov analysis on the new function.
  • Add a new workflow to run codacy analysis on the new function.
  • Add a new workflow to run codeclimate analysis on the new function.
  • Add a new workflow to run codeql analysis on the new function.
  • Add a new workflow to run snyk analysis on the new function.
  • Add a new workflow to run pytype analysis on the new function.
  • Add a new workflow to run mypy analysis on the new function.
  • Add a new workflow to run pydocstyle analysis on the new function.
  • Add a new workflow to run pylint analysis on the new function.
  • Add a new workflow to run flake8 analysis on the new function.
  • Add a new workflow to run yamllint analysis on the new function.
  • Add a new workflow to run markdownlint analysis on the new function.
  • Add a new workflow to run pytest analysis on the new function.

Bug Fixes:

  • Fix a bug in the make_spiral function where the spiral was not being generated correctly.
  • Fix a bug in the validate_battlefield function where some valid battlefields were being rejected.
  • Fix a bug in the Sudoku validator where 1x1 Sudokus with incorrect values were not being rejected.
  • Fix a bug in the calculate function where additional spaces caused incorrect calculations

Enhancements:

  • Improve the performance of the make_spiral function by optimizing the conditions.
  • Improve the readability of the validate_battlefield function by simplifying the logic.
  • Improve the error handling in the calculate function by using ASTEVAL.
  • Improve the test coverage for the Sudoku validator by adding more test cases.
  • Improve the CI pipeline by adding more linters and formatters.
  • Improve the documentation for the potion class by adding type hints.
  • Improve the readability of the epidemic function by using more descriptive variable names.
  • Simplify the starting value calculation in the sol_equa function.
  • Improve the test descriptions in test_generate_hashtag and test_unique_in_order.
  • Improve the error messages in test_tickets.
  • Improve the documentation for the how_many_dalmatians function.
  • Add a new kata solution for 'Replace With Alphabet Position'.

Documentation:

  • Update the list of completed katas in the README.
  • Add documentation for the ASTEVAL library.
  • Add documentation for the how_many_dalmatians function.
  • Add a new kata solution for 'Replace With Alphabet Position'.

Tests:

  • Add tests for 'Replace With Alphabet Position' kata solution.
  • Remove duplicate and unnecessary test cases in test_sudoku.py.
  • Update test descriptions in test_string_transformer.py, test_has_subpattern.py, and test_tickets.py to use multiline strings.
  • Update test descriptions in test_generate_hashtag.py and test_unique_in_order.py for better clarity.
  • Update test data and assertions in test_calculate_damage.py for consistency.
  • Add a test case for empty string input in test_replace_with_alphabet_position.py.

Chores:

  • Remove unnecessary blank lines and trailing whitespace from Python files.
  • Refactor multiple conditions into separate functions for better readability and maintainability in make_spiral.
  • Simplify the return statement in validate_battlefield using all().
  • Remove duplicate and unnecessary test cases from test_sudoku.py.
  • Update the CI pipeline to lint, test, and build only on the main branch.
  • Update the Codecov, Code Climate, and Codacy workflows to run on pull_request_target events.
  • Update the Pytest workflow to upload artifacts only on failure.
  • Update the MyPy, Pydocstyle, Flake8, and Pylint workflows to run on all branches except utils.
  • Update the Markdown lint workflow to run on the Documentation branch.
  • Update the Yamllint config to increase the maximum line length to 90.
  • Update documentation for the potion class to include type hints.
  • Update the epidemic function to use more descriptive variable names and simplify the calculations.
  • Update the sol_equa function to simplify the starting value calculation.
  • Update the calculate_damage function to use consistent spacing.
  • Update the warrior class to simplify the experience update logic.
  • Update the Sudoku class to simplify the data validation logic.
  • Update the string_transformer and has_subpattern test cases to use multiline strings.
  • Update the tickets test case to use multiline strings.
  • Add documentation for the how_many_dalmatians function.
  • Add a new kata solution for 'Replace With Alphabet Position'.

ikostan and others added 14 commits February 15, 2025 18:10
./kyu_6/disease_spread/epidemic.py:48:33: W504 line break after binary operator
            susceptible[k] - dt *
                                ^
./kyu_6/disease_spread/epidemic.py:49:25: W504 line break after binary operator
            kwargs['b'] *
                        ^
./kyu_6/disease_spread/epidemic.py:50:28: W504 line break after binary operator
            susceptible[k] *
                           ^
./kyu_6/disease_spread/epidemic.py:54:31: W504 line break after binary operator
            infecteds[k] + dt *
                              ^
./kyu_6/disease_spread/epidemic.py:55:26: W504 line break after binary operator
            (kwargs['b'] *
                         ^
./kyu_6/disease_spread/epidemic.py:56:29: W504 line break after binary operator
             susceptible[k] *
                            ^
./kyu_6/disease_spread/epidemic.py:57:41: W504 line break after binary operator
             infecteds[k] - kwargs['a'] *
Run python -m flake8 ./kyu_6 --count --benchmark --show-source --statistics
./kyu_6/disease_spread/epidemic.py:48:17: E126 continuation line over-indented for hanging indent
                susceptible[k] - dt * kwargs['b'] * susceptible[k] * infecteds[k]
                ^
./kyu_6/disease_spread/epidemic.py:53:17: E126 continuation line over-indented for hanging indent
                infecteds[k] + dt *
                ^
./kyu_6/disease_spread/epidemic.py:53:35: W504 line break after binary operator
                infecteds[k] + dt *
                                  ^
Run python -m flake8 ./kyu_6 --count --benchmark --show-source --statistics
./kyu_6/disease_spread/epidemic.py:53:31: W504 line break after binary operator
            infecteds[k] + dt *
                              ^
Run python -m flake8 ./kyu_6 --count --benchmark --show-source --statistics
./kyu_6/potion_class_101/potion.py:52:24: W503 line break before binary operator
                       * self.volume) / (other.volume + self.volume))
                       ^
./kyu_6/potion_class_101/potion.py:54:24: W503 line break before binary operator
                       * self.volume) / (other.volume + self.volume))
                       ^
./kyu_6/potion_class_101/potion.py:56:24: W503 line break before binary operator
                       * self.volume) / (other.volume + self.volume))
                       ^
3     W503 line break before binary operator
0.313      seconds elapsed
Run python -m flake8 ./kyu_6 --count --benchmark --show-source --statistics
./kyu_6/potion_class_101/potion.py:52:75: W504 line break after binary operator
            (other.color[0] * other.volume + self.color[0] * self.volume) /
                                                                          ^
./kyu_6/potion_class_101/potion.py:56:75: W504 line break after binary operator
            (other.color[1] * other.volume + self.color[1] * self.volume) /
                                                                          ^
./kyu_6/potion_class_101/potion.py:60:75: W504 line break after binary operator
            (other.color[2] * other.volume + self.color[2] * self.volume) /
                                                                          ^
3     W504 line break after binary operator
0.319      seconds elapsed
Run python -m flake8 ./kyu_6 --count --benchmark --show-source --statistics
./kyu_6/potion_class_101/potion.py:10:1: F401 'typing.ClassVar' imported but unused
from typing import Tuple, ClassVar
^
1     F401 'typing.ClassVar' imported but unused
0.32       seconds elapsed
./kyu_6/potion_class_101/potion.py:63 in private method `__calc_rgb`:
        D205: 1 blank line required between summary line and description (found 0)

Multi-line docstrings consist of a summary line just like a one-line
docstring, followed by a blank line, followed by a more elaborate
description. The summary line may be used by automatic indexing tools;
it is important that it fits on one line and is separated from the
rest of the docstring by a blank line.
Run python -m flake8 ./kyu_6 --count --benchmark --show-source --statistics
./kyu_6/potion_class_101/potion.py:65:1: W293 blank line contains whitespace
        """
        Calculate RGB values.

        :param index: int
        :param other: Object
        :param total_volume: int
        :return:
        """
^
1     W293 blank line contains whitespace
Merge pull request #644 from iKostanOrg/master
@sourcery-ai
Copy link
Contributor

sourcery-ai bot commented Feb 16, 2025

Reviewer's Guide by Sourcery

This pull request refactors the codebase by introducing helper functions for condition checks, optimizes the workflow configurations, and enhances the test coverage. It also includes the addition of a new feature for replacing letters with their alphabet positions.

Sequence diagram for mixing two potions

sequenceDiagram
    participant Potion1
    participant Potion2
    Potion1->>Potion1: mix(Potion2)
    Potion1->>Potion1: __calc_rgb(Potion2, new_volume)
    Potion1->>Potion2: other.color
    Potion1->>Potion2: other.volume
    Potion1-->>Potion1: r, g, b
    Potion1-->>Potion1: Potion((r, g, b), new_volume)
    Potion1-->>Potion1: return new Potion
Loading

Updated class diagram for Potion Class

classDiagram
    class Potion {
        - Tuple[int, int, int] color
        - int volume
        + __init__(color: Tuple[int, int, int], volume: int)
        + mix(other: Potion) : Potion
        + volume() : int
        + volume(value: int) : None
        + color() : Tuple[int, int, int]
        - __calc_rgb(other: Potion, new_volume: int) : Tuple[int, int, int]
    }
Loading

File-Level Changes

Change Details Files
Refactored condition checks in the make_spiral solution.
  • Removed inline condition checks and replaced them with dedicated functions.
  • Simplified the logic in the right function by using helper functions for conditions.
kyu_3/make_spiral/solution.py
Removed redundant test cases in the validate_sudoku_with_size tests.
  • Deleted duplicate and unnecessary test cases to streamline the test suite.
kyu_4/validate_sudoku_with_size/test_sudoku.py
Optimized the battleship field validator logic.
  • Replaced multiple if conditions with a single all() function call for ship validation.
  • Refactored ship counting logic to improve readability and maintainability.
kyu_3/battleship_field_validator/validator.py
Updated the README for kyu_6 to include a new kata.
  • Added a new entry for 'Replace With Alphabet Position' in the completed kata list.
kyu_6/README.md
Enhanced GitHub Actions workflows for better CI/CD.
  • Added timeout settings to prevent indefinite runs.
  • Separated pytype checks into individual workflows for different kyu levels.
  • Updated branch triggers and permissions for workflows.
.github/workflows/lint_test_build_pipeline.yml
.github/workflows/codecov.yml
.github/workflows/codacy-coverage-reporter.yaml
.github/workflows/pytest.yml
.github/workflows/mypy.yml
.github/workflows/pytype.yml
.github/workflows/codeclimate_coverage.yml
.github/workflows/pydocstyle.yml
.github/workflows/flake8.yml
.github/workflows/flake8_kyu6.yml
.github/workflows/mypy_kyu4.yml
.github/workflows/mypy_kyu5.yml
.github/workflows/mypy_kyu6.yml
.github/workflows/pydocstyle_kyu6.yml
.github/workflows/yamllint.yml
.github/workflows/pydocstyle_kyu5.yml
.github/workflows/pylint_kyu6.yml
.github/workflows/flake8_kyu2.yml
.github/workflows/flake8_kyu3.yml
.github/workflows/pydocstyle_kyu2.yml
.github/workflows/pydocstyle_kyu3.yml
.github/workflows/pydocstyle_kyu4.yml
.github/workflows/pylint.yml
.github/workflows/pylint_kyu4.yml
.github/workflows/flake8_kyu4.yml
.github/workflows/flake8_kyu5.yml
.github/workflows/pylint_kyu5.yml
.github/workflows/mypy_kyu2.yml
.github/workflows/pytype_kyu7.yml
.github/workflows/snyk.yml
.github/workflows/mypy_kyu3.yml
.github/workflows/pylint_kyu3.yml
.github/workflows/codeql.yml
.github/workflows/pydocstyle_kyu8.yml
.github/workflows/flake8_kyu8.yml
.github/workflows/pylint_kyu8.yml
.github/workflows/pytype_kyu8.yml
.github/workflows/pytype_kyu2.yml
.github/workflows/pytype_kyu3.yml
.github/workflows/pytype_kyu4.yml
.github/workflows/pytype_kyu5.yml
.github/workflows/pytest_kyu2.yml
.github/workflows/pytest_kyu3.yml
.github/workflows/pytest_kyu4.yml
.github/workflows/pytest_kyu5.yml
.github/workflows/pytest_kyu6.yml
.github/workflows/codeclimate_qlty_coverage.yml
Introduced a new feature for replacing letters with their alphabet positions.
  • Implemented a new function to replace each letter in a string with its corresponding position in the alphabet.
  • Added unit tests for the new feature to ensure correctness.
kyu_6/replace_with_alphabet_position/solution.py
kyu_6/replace_with_alphabet_position/test_replace_with_alphabet_position.py
kyu_6/replace_with_alphabet_position/README.md

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!
  • Generate a plan of action for an issue: Comment @sourcery-ai plan on
    an issue to generate a plan of action for it.

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @ikostan - I've reviewed your changes - here's some feedback:

Overall Comments:

  • Consider using more descriptive names for functions like get_condition_0 to improve readability.
  • The battleship validator could be simplified by extracting the ship counting logic into a separate function.
  • The addition of ASTEVAL in the basic math problem is a good way to avoid security issues with eval.
Here's what I looked at during the review
  • 🟡 General issues: 1 issue found
  • 🟢 Security: all looks good
  • 🟡 Testing: 2 issues found
  • 🟡 Complexity: 1 issue found
  • 🟢 Documentation: all looks good

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

row = coordinates['row']
col = coordinates['col']

if col == len(spiral[0]) - 1 and \
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

issue (complexity): Consider inlining the helper functions and merging similar conditional checks to reduce fragmentation and improve readability.

You can reduce fragmentation by inlining the trivial conditions with clear inline comments instead of using six tiny helper functions. For example, instead of writing:

if get_condition_0(spiral, row, col):
    spiral[row][col] = 1
    coordinates['col'] += 1
    done = False
    break

you could consolidate that logic right in the main function:

# Condition 0: if next cell is the last in the row and is empty, move and mark current cell.
if col + 1 == len(spiral[0]) - 1 and spiral[row][col + 1] == spiral[row][col] == 0:
    spiral[row][col] = 1
    coordinates['col'] += 1
    done = False
    break

Similarly, if multiple conditions have similar structure, merge them into a single if/elif block with comments. For example:

# Check conditions for breaking (conditions 1 to 3)
if (col == len(spiral[0]) - 1 and spiral[row][col] == 0) or \
   (col + 2 == len(spiral[0]) - 1 and spiral[row][col + 2] == 1 and 
       spiral[row][col + 1] == spiral[row][col] == 0) or \
   (col + 2 < len(spiral[0]) - 1 and spiral[row][col + 2] == 1 and 
       spiral[row][col + 1] == spiral[row][col] == 0 and 
       col + 2 < len(spiral[0]) and spiral[row + 1][col] != 1):
    spiral[row][col] = 1
    done = False
    break

This approach keeps the functionality intact while reducing extra indirections and making the core logic easier to follow.

@qltysh
Copy link

qltysh bot commented Feb 16, 2025

❌ 61 blocking issues (72 total)

Tool Category Rule Count
prettier Style Incorrect formatting, autoformat by running `qlty fmt`. 61
qlty Structure Function with high complexity (count = 16): ship_counter_by_row 6
qlty Structure Deeply nested control flow (level = 4) 2
qlty Duplication Found 17 lines of similar code in 2 locations (mass = 74) 2
qlty Structure High total complexity (count = 62) 1

@qltysh one-click actions:

  • Auto-fix formatting (qlty fmt && git push)
    qlty successfully analyzed this pull request in 4m.

suggestion (testing): Add more test cases for edge cases and non-alpha characters

It would be beneficial to include test cases with special characters like "!@#$%^&*()_+=-`~[]{}|;':",./<>?", numbers, and a mix of alphanumeric and special characters to ensure comprehensive test coverage.

Suggested implementation:

    @parameterized.expand([
        ("", ""),
        ("123", ""),
        ("!@#$%^&*()", ""),
        ("a1!b", "1 2"),
        ("AbZ!", "1 2 26"),
    ])
    def test_alphabet_position(self, string, expected):
        """
        Testing 'alphabet_position' function with various edge cases including empty strings,
        numbers, special characters, and mixed alphanumeric input.
        """
        # pylint: disable-msg=R0801
        allure.dynamic.title("Testing the 'alphabet_position' with edge cases")
Ensure that the expected results match the behavior of the alphabet_position function in cases involving non-alpha characters. If the function behavior is different from assumed here, adjust the expected outputs accordingly.
@ikostan ikostan added the kyu_4 label Feb 16, 2025
suggestion (testing): Missing tests for invalid 1x1 Sudoku

While there's a test for a valid 1x1, there are no tests for invalid 1x1 scenarios (e.g., with values other than 1 or with non-integer values). Add tests to cover these cases.

Suggested change
            ([[1]], True, 'Testing valid 1x1'),
            ([[1]], True, 'Testing valid 1x1'),
            ([[2]], False, 'Testing invalid 1x1 with wrong value'),
            (([['a']], False, 'Testing invalid 1x1 with non-integer value'),
@ikostan ikostan added this to the kyu_7 linting fixes milestone Feb 16, 2025
@ikostan ikostan merged commit 836614d into kyu7 Feb 16, 2025
30 of 34 checks passed
ikostan added a commit that referenced this pull request Feb 16, 2025
Merge pull request #646 from iKostanOrg/master
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants