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

feat: integer repeat #237

Merged
merged 4 commits into from
Dec 12, 2024
Merged

Conversation

Flix6x
Copy link
Contributor

@Flix6x Flix6x commented Apr 24, 2023

Closes #234.

@@ -471,6 +471,10 @@ async def match(

if matcher.repeat is False:
del self._matches[key]
elif matcher.repeat == 2:
Copy link
Owner

Choose a reason for hiding this comment

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

why equal to 2?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Because I meant repeat=1 to have the same effect as repeat=False. That is, I interpret the number of repetitions to include the first call. I guess an alternative would be to define the number of repetitions as the number after the first call.

That is, for repeat=5, either:

  • respond 5 times with foo
  • respond with foo, and also do that the next 5 times (so 6 in total)

The former seems more intuitive to me.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The repeat=1 case was actually broken. I fixed it and added a test. I also elaborated on this matter in the main README.

@diogenesc
Copy link

This feature would be very much appreciated 👍

@@ -469,8 +469,12 @@ async def match(
else:
return None

if matcher.repeat is False:
if matcher.repeat in (False, 1):
Copy link
Owner

Choose a reason for hiding this comment

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

test are not working and this part is bugged.
when repeat is set to True the if statement does not work [True in (False, 1) returns True].

IMO we should have

if isinstance(matcher.repeat, bool):
    if not matcher.repeat:
        del self._matches[key]
else:
    if matcher.repeat == 1:
        del self._matches[key]
    matcher.repeat -= 1

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Great suggestion, much cleaner. I'll gladly fix it. Just give me a few days, please (got a project deadline).

Copy link
Owner

@pnuckowski pnuckowski left a comment

Choose a reason for hiding this comment

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

Need to fix tests. Let me know if you fix this or should I fixed this :) ?

if isinstance(matcher.repeat, bool):
    if not matcher.repeat:
        del self._matches[key]
else:
    if matcher.repeat == 1:
        del self._matches[key]
    matcher.repeat -= 1

@Flix6x Flix6x requested a review from pnuckowski May 10, 2024 09:25
@pnuckowski pnuckowski merged commit bf6c60e into pnuckowski:master Dec 12, 2024
20 checks passed
@Flix6x Flix6x deleted the integer-repeat-option branch December 12, 2024 08:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

repeat option in get(), post(), etc. also accept int
4 participants