TheDigitalCatOnline / blog_source

Source code of the blog
16 stars 6 forks source link

Replace lambda with `operator.mul` #14

Closed blablatdinov closed 1 year ago

blablatdinov commented 1 year ago

Hello, I read your article about TDD and found a place where the operator.mul function looks more appropriate. I want to create a PR if the author agree with this opinion

https://github.com/TheDigitalCatOnline/blog_source/blob/9f28de64f127f0f765c0d6e53fb751e5f987697a/pelican/content/tdd-in-python-with-pytest-part-1.mau#L810

lgiordani commented 1 year ago

Hi @blablatdinov, thanks for the message. I'm not sure operator.mul will actually simplify that expression, how do you plan to use it? Can you attach an example here? Thanks!

blablatdinov commented 1 year ago

Yes, it will look something like this:

import operator
from functools import reduce

class SimpleCalculator:
    [...]

    def mul(self, *args):
        return reduce(operator.mul, args)
lgiordani commented 1 year ago

Oh, I see what you mean now. Sorry, for some reason I thought you wanted to replace reduce... Don't mind me. Thanks, good suggestion. No need to send a PR, I will add it to the post. I will leave this open until I fixed it.

Thanks!

lgiordani commented 1 year ago

Hi @blablatdinov! I fixed this in the post and in the code you find on GitHub. Thanks for the suggestion and apologies for the long delay!