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

Add get_request_kwargs to check before requesting #339

Merged
merged 1 commit into from Nov 11, 2020

Conversation

kumarstack55
Copy link
Contributor

When we use mechanicalsoup, we sometimes want to verify a request before submitting it.

If you merge this pull request, the package will be able to provide a way for the package's users to review the request.

This is my first pull request for this project. Please let me know if I'm missing anything.

Copy link
Contributor

@hemberger hemberger left a comment

Choose a reason for hiding this comment

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

Hi, and thanks for your contribution to MechanicalSoup!

In principle, I think this is a fine change. I've recommended one small spelling error and identified a corner case that probably needs to be addressed. Once those are fixed, I will be ready to approve this. Then if the other maintainer approves as well we can merge it in. :)

mechanicalsoup/browser.py Outdated Show resolved Hide resolved
mechanicalsoup/browser.py Outdated Show resolved Hide resolved
kumarstack55 added a commit to kumarstack55/MechanicalSoup that referenced this pull request Oct 17, 2020
kumarstack55 added a commit to kumarstack55/MechanicalSoup that referenced this pull request Oct 17, 2020
@kumarstack55
Copy link
Contributor Author

The group of jobs in travisci are listed as Queued, but when I click on Details to check, it looks like all the jobs are successful.

@kumarstack55
Copy link
Contributor Author

The group of jobs in travisci are listed as Queued, but when I click on Details to check, it looks like all the jobs are successful.

@hemberger Is there anything else I should do? :)

@moy moy changed the title Add _get_reuqest_kwargs to check before requesting Add _get_request_kwargs to check before requesting Oct 17, 2020
@moy
Copy link
Collaborator

moy commented Oct 17, 2020

Commits should be squashed and the typo should be fixed in the commits summary (I just fixed it in the PR title). We keep a clean history hence a PR should include several commits only if the change needs to be split into several commits, not as leftover of previous mistakes.

Copy link
Collaborator

@moy moy left a comment

Choose a reason for hiding this comment

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

On overall, this looks good, but a few more nits to be fixed before this can be merged.

def _request(self, form, url=None, **kwargs):
"""Extract input data from the form to pass to a Requests session."""
@classmethod
def _get_request_kwargs(cls, method, url, **kwargs):
Copy link
Collaborator

Choose a reason for hiding this comment

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

cls is unused here, right? Why not use @staticmethod instead of @classmethod then?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for the good point. I'll use @staticmethod to avoid making cls useless.

@classmethod
def _get_request_kwargs(cls, method, url, **kwargs):
# This method exists to raise a TypeError when a method or url is
# specified in the kwargs.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Shouldn't this comment be a docstring?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Actually, this is my first time writing a docstring.

I'll be referring to other methods to write docstrings. Please let me know if you have any concerns.

try:
browser.get_request_kwargs(form, page.url, **kwargs)
except TypeError:
type_error_raised = True
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please use pytest.raises to assert that an exception is raised.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks, I'll rewrite it using pytest.raises.

# pylint: disable=redundant-keyword-arg
browser.get_request_kwargs(form, page.url, **kwargs)
except TypeError:
type_error_raised = True
Copy link
Collaborator

Choose a reason for hiding this comment

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

Likewise.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks, I'll rewrite it using pytest.raises.

@kumarstack55
Copy link
Contributor Author

Originally, this pull request was intended to implement _get_request_kwargs(), but the name was changed and get_request_kwargs() is the current name.

Therefore, please let me change the title of the Pull Request.

@kumarstack55 kumarstack55 changed the title Add _get_request_kwargs to check before requesting Add get_request_kwargs to check before requesting Oct 18, 2020
@kumarstack55
Copy link
Contributor Author

Commits should be squashed and the typo should be fixed in the commits summary (I just fixed it in the PR title).

I squashed the commits to one. ✨

@moy
Copy link
Collaborator

moy commented Oct 19, 2020

On overall this looks good to me. The commit message would deserve a bit more love I think (explain why the change is needed and good).

@kumarstack55
Copy link
Contributor Author

On overall this looks good to me. The commit message would deserve a bit more love I think (explain why the change is needed and good).

Let me make the commit log more understandable and lovely. I don't plan to make any changes to the code at this time.

@kumarstack55
Copy link
Contributor Author

@hemberger @moy Let me know if there's anything else I need to do to get the pull request merged.

Copy link
Contributor

@hemberger hemberger left a comment

Choose a reason for hiding this comment

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

Overall, the changes look great. I've identified one simple change I'd like to see, but then I think this is ready to be merged. Thanks!

mechanicalsoup/browser.py Show resolved Hide resolved
Previously, users had no way to check what request data is
sent to the server before submitting a form. By calling
get_request_kwargs(), the user can see the request data
without having to send to.
@hemberger hemberger merged commit e6da833 into MechanicalSoup:master Nov 11, 2020
@hemberger
Copy link
Contributor

Thanks again for your contribution!

@kumarstack55
Copy link
Contributor Author

Thank you for merging. 😄

By the way, it occurs to me that this was the first time in my life that I've ever had my code reviewed.
I don't have a job writing programs. Furthermore, I had never even written a docstring before.
(I do some scraping as a hobby, so having Mechanicalsoup available would be very helpful. )

For me, all of the points you @hemberger @moy have given me are excellent. ✨
I'm sure it would be very difficult for you to review my code.
Thanks to your thoughtful comments, I managed to get it merged.

Again, thank you for the series of responses and for merging my request. 👍

@moy
Copy link
Collaborator

moy commented Nov 12, 2020

Thanks for the feedback. In another life, I'm a teacher, and that's what I try to explain my students: code review is not "I went through it and it doesn't look too bad", but can be much more picky and constructive than that ;-).

ism pushed a commit to ism/MechanicalSoup that referenced this pull request Mar 4, 2021
Previously, users had no way to check what request data is
sent to the server before submitting a form. By calling
get_request_kwargs(), the user can see the request data
without having to send to.
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

3 participants