Skip to content

Commit

Permalink
Rename sum to calc_sum to avoid name conflicts with built-in sum
Browse files Browse the repository at this point in the history
  • Loading branch information
31ch committed Jan 4, 2025
1 parent f5d5b52 commit 3784eee
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 11 deletions.
4 changes: 2 additions & 2 deletions src/python_training_project/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import click

from python_training_project.calculate import sum
from python_training_project.calculate import calc_sum

log = logging.getLogger(__name__)

Expand All @@ -28,7 +28,7 @@ def cli():
@click.argument("b", type=float)
def cli_sum(a: float, b: float):
"""Show the sum of two numbers on the console."""
log.info("Sum of %f and %f is %f", a, b, sum(a, b))
log.info("Sum of %f and %f is %f", a, b, calc_sum(a, b))


if __name__ == "__main__":
Expand Down
2 changes: 1 addition & 1 deletion src/python_training_project/calculate.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"""


def sum(a: float, b: float) -> float:
def calc_sum(a: float, b: float) -> float:
"""Calculate the sum of two numbers."""
return a + b

Expand Down
16 changes: 8 additions & 8 deletions tests/test_calculate.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
from python_training_project.calculate import sum
from python_training_project.calculate import calc_sum


def test_sum():
assert sum(1, 1) == 2
assert sum(2, 1) == 3
assert sum(1, 2) == 3
def test_calc_sum():
assert calc_sum(1, 1) == 2
assert calc_sum(2, 1) == 3
assert calc_sum(1, 2) == 3


def test_sum_negative():
assert sum(1, -1) == 0
assert sum(-1, 1) == 0
assert sum(-1, -1) == -2
assert calc_sum(1, -1) == 0
assert calc_sum(-1, 1) == 0
assert calc_sum(-1, -1) == -2

0 comments on commit 3784eee

Please sign in to comment.