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

refactor: move response_content into backend code #2488

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

nejch
Copy link
Member

@nejch nejch commented Feb 12, 2023

Needed in order to later add other backends that handle streaming responses differently. Just a first step, later maybe we could get rid of response_content completely from individual methods and just handle this in the request code 🤔

@codecov-commenter
Copy link

codecov-commenter commented Feb 12, 2023

Codecov Report

Attention: Patch coverage is 87.17949% with 5 lines in your changes missing coverage. Please review.

Project coverage is 96.10%. Comparing base (7ec3189) to head (24ba442).
Report is 80 commits behind head on main.

Current head 24ba442 differs from pull request most recent head a8c95c8

Please upload reports for the commit a8c95c8 to get more accurate results.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2488      +/-   ##
==========================================
- Coverage   96.52%   96.10%   -0.43%     
==========================================
  Files          90       87       -3     
  Lines        5872     5667     -205     
==========================================
- Hits         5668     5446     -222     
- Misses        204      221      +17     
Flag Coverage Δ
api_func_v4 82.47% <71.79%> (+0.23%) ⬆️
cli_func_v4 82.93% <48.71%> (-0.65%) ⬇️
unit 87.55% <69.23%> (-0.75%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files Coverage Δ
gitlab/_backends/requests_backend.py 96.92% <100.00%> (-1.89%) ⬇️
gitlab/mixins.py 92.05% <100.00%> (-0.87%) ⬇️
gitlab/v4/objects/artifacts.py 100.00% <100.00%> (ø)
gitlab/v4/objects/files.py 100.00% <100.00%> (ø)
gitlab/v4/objects/packages.py 96.22% <100.00%> (-3.78%) ⬇️
gitlab/v4/objects/projects.py 98.86% <100.00%> (+0.07%) ⬆️
gitlab/v4/objects/repositories.py 83.56% <100.00%> (ø)
gitlab/v4/objects/secure_files.py 100.00% <100.00%> (ø)
gitlab/v4/objects/snippets.py 97.95% <100.00%> (-0.05%) ⬇️
gitlab/_backends/protocol.py 80.00% <80.00%> (-12.86%) ⬇️
... and 2 more

... and 29 files with indirect coverage changes

@nejch nejch force-pushed the refactor/response-content-backend branch from 70a5cfd to 940e59c Compare February 12, 2023 16:03
gitlab/_backends/requests_backend.py Outdated Show resolved Hide resolved
@nejch nejch force-pushed the refactor/response-content-backend branch from 940e59c to 4dc7f00 Compare February 15, 2023 23:01
@nejch nejch marked this pull request as ready for review February 15, 2023 23:03
@nejch nejch force-pushed the refactor/response-content-backend branch 7 times, most recently from 0f907b9 to ab089fb Compare March 12, 2023 08:40
@nejch nejch force-pushed the refactor/response-content-backend branch from ab089fb to a8c95c8 Compare June 8, 2024 15:38
@nejch
Copy link
Member Author

nejch commented Jun 8, 2024

@JohnVillalovos I've rebased and reworked this a bit based on previous comments. Would you be able to have a look at this one?

IMO it's also a bit cleaner like this to have the response logic be part of the client/backend than a separate util function since we've split out the client code (and more recently the backend code) from the monolith __init__ module.

@nejch nejch requested a review from JohnVillalovos June 8, 2024 15:46
Copy link
Member

@JohnVillalovos JohnVillalovos left a comment

Choose a reason for hiding this comment

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

Thanks @nejch

Overall looks good to me. Only a couple of nits on my end. But I would be okay with merging as is. So approved by me.

@@ -17,6 +17,17 @@ def __init__(self, response: requests.Response) -> None: ...


class Backend(Protocol):
@staticmethod
@abc.abstractmethod
def response_content(
Copy link
Member

Choose a reason for hiding this comment

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

This seems like it might be a good time to make the method require keyword args for all the args. I'm a fan of requiring keyword args 😆

Copy link
Member Author

Choose a reason for hiding this comment

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

I believe this would be a breaking change as we still expose it in utils as a non-private function. In that case I'd maybe drop the wrapper entirely and not just deprecate it, as then we don't need to worry about maintaining the signature twice (#2488 (comment)).

Might be worth grouping breaking changes and wait to merge them all together though for a major release.

Copy link
Member

Choose a reason for hiding this comment

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

Well I didn't think it would be a breaking change if this is the new function and then the wrapper (with the deprecation) would call this one with keyword args.

chunk_size: int,
*,
iterator: bool,
*args: Any, **kwargs: Any
Copy link
Member

Choose a reason for hiding this comment

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

I would prefer to keep the signature as before. Instead of using *args/**kwargs.

Copy link
Member Author

Choose a reason for hiding this comment

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

My initial idea was to just leave a simple wrapper for backward compatibility but maybe we can just drop it (see #2488 (comment)).

Copy link
Member

Choose a reason for hiding this comment

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

My thought was that this one would maintain the same exact signature as before, and then call the new function with keyword arguments.

But! It isn't that important and perfectly fine with me if you want to merge this in as is 👍

Copy link
Member Author

Choose a reason for hiding this comment

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

Ahh I misunderstood your comment I think, I thought you wanted to match the signatures. I'll add the changes!

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.

None yet

4 participants