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 missing-timeout warning for requests.Session object #9526

Open
wants to merge 9 commits into
base: main
Choose a base branch
from

Conversation

joel6948
Copy link

@joel6948 joel6948 commented Apr 1, 2024

some issue fixes
#9517 for this issue

@Pierre-Sassoulas Pierre-Sassoulas added the False Negative 🦋 No message is emitted but something is wrong with the code label Apr 1, 2024
@Pierre-Sassoulas Pierre-Sassoulas added this to the 3.2.0 milestone Apr 1, 2024
Copy link
Member

@Pierre-Sassoulas Pierre-Sassoulas left a comment

Choose a reason for hiding this comment

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

Thank you for your contribution @joel6948, do you mind expanding missing-timeout instead of creating a new extension please ?

@joel6948
Copy link
Author

joel6948 commented Apr 1, 2024

Thank you for your contribution @joel6948, do you mind expanding missing-timeout instead of creating a new extension please ?

sure

@joel6948
Copy link
Author

joel6948 commented Apr 1, 2024

Thank you for your contribution @joel6948, do you mind expanding missing-timeout instead of creating a new extension please ?

#9527 (comment)
done

@Pierre-Sassoulas Pierre-Sassoulas changed the title Issue fixed Add missing-timeout warning for requests.Session object Apr 1, 2024
@@ -71,13 +71,11 @@ class MethodArgsChecker(BaseChecker):
)
def visit_call(self, node: nodes.Call) -> None:
self._check_missing_timeout(node)
self._check_positional_only_arguments_expected(node)
# Other checks...
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
# Other checks...
self._check_positional_only_arguments_expected(node)

This should stay, you can delete pylint/extensions/requests_timeout_plugin.py and add your use case in _check_missing_timeout directly (without adding a new message, just use the existing missing-timeout).

Copy link
Author

Choose a reason for hiding this comment

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

done

Copy link
Member

Choose a reason for hiding this comment

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

I think you added a python file in the documentation, but you need to modify the code / add your logic here instead:

def _check_missing_timeout(self, node: nodes.Call) -> None:
"""Check if the call needs a timeout parameter based on package.func_name
configured in config.timeout_methods.
Package uses inferred node in order to know the package imported.
"""
inferred = utils.safe_infer(node.func)
call_site = arguments.CallSite.from_call(node)
if (
inferred
and not call_site.has_invalid_keywords()
and isinstance(
inferred, (nodes.FunctionDef, nodes.ClassDef, bases.UnboundMethod)
)
and inferred.qname() in self.linter.config.timeout_methods
):
keyword_arguments = [keyword.arg for keyword in node.keywords]
keyword_arguments.extend(call_site.keyword_arguments)
if "timeout" not in keyword_arguments:
self.add_message(
"missing-timeout",
node=node,
args=(node.func.as_string(),),
confidence=INFERENCE,
)

Please note that we're using inference which can handle case where a variable is used and not request.Session directly.

Copy link
Author

Choose a reason for hiding this comment

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

but in the main branch is it showing inference which can handle case where a variable is used and not request.Session directly. or is it my mistake

Copy link
Member

Choose a reason for hiding this comment

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

Hmm, not sure. I think we handle a call to request.get (and other see self.linter.config.timeout_methods) (directly or inferred) but not Session. It should be able to do both (?). Maybe the solution is as simple as changing the default for timeout_methods

Copy link
Author

Choose a reason for hiding this comment

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

i did the change a bit can you is it working

Copy link
Member

Choose a reason for hiding this comment

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

@Pierre-Sassoulas
Copy link
Member

You're also going to need to add a changelog entry, see:

create a news fragment with towncrier create . which will be included in the changelog. can be one of the types defined in ./towncrier.toml. If necessary you can write details or offer examples on how the new change is supposed to work.
https://pylint.readthedocs.io/en/stable/development_guide/contributor_guide/contribute.html#creating-a-pull-request

Copy link
Contributor

github-actions bot commented Apr 2, 2024

🤖 According to the primer, this change has no effect on the checked open source code. 🤖🎉

This comment was generated for commit 9f99786

@Pierre-Sassoulas Pierre-Sassoulas added the Waiting on author Indicate that maintainers are waiting for a message of the author label May 4, 2024
@jacobtylerwalls jacobtylerwalls modified the milestones: 3.2.0, 3.3.0 May 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
False Negative 🦋 No message is emitted but something is wrong with the code Waiting on author Indicate that maintainers are waiting for a message of the author
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants