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

#6: add indexing to BodyOfTheLastResponse. #7

Merged
merged 9 commits into from
Feb 13, 2024

Conversation

perrygoy
Copy link
Member

This PR adds __getitem__ handling for BodyOfTheLastResponse, which does two things:

  1. Adds the requested index to the list of body_parts (sorry i couldn't help myself).
  2. Returns self.

This means further indexing will be kept track of in the body_parts list. As the question is answered, BodyOfTheLastResponse checks if it has any body_parts, and will travel down the list for the user while answering the Question.

One thing for discussion—should a KeyError or IndexError just be let to bubble up, or should we catch that and tell the user what went wrong?

@perrygoy perrygoy requested a review from a team February 12, 2024 22:21
@@ -23,11 +23,11 @@ def generate_send_method_class(method: str) -> Type[APIMethodAction]:
"""

class SendMETHODRequest:
"Will be programmatically replaced."
"""Will be programmatically replaced."""
Copy link
Member Author

Choose a reason for hiding this comment

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

Oh yeah also i had this fix here for months. Haha.

Choose a reason for hiding this comment

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

I figure when we add ruff to the project, all these would be updated anyway.

@@ -53,6 +52,32 @@ def test_ask_for_body_of_the_last_response(self, APITester):

assert BodyOfTheLastResponse().answered_by(APITester) == test_json

def test_stores_index_path(self):
botlr = BodyOfTheLastResponse()["shuffled"]["off"][10]["mortal"]["coils"]

Choose a reason for hiding this comment

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

I would add a slice here.

@MarcelWilson
Copy link

Looks good! Only have one last suggestion: add a slice example to test_stores_index_path

Copy link
Contributor

@bandophahita bandophahita left a comment

Choose a reason for hiding this comment

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

Very clever sir.

@perrygoy perrygoy merged commit f164c41 into trunk Feb 13, 2024
25 checks passed
@perrygoy perrygoy deleted the 6/add-indexing-to-bodyofthelastrequest branch February 13, 2024 21:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants