-
Notifications
You must be signed in to change notification settings - Fork 0
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
fixed passing context argument to is_observed #607
Conversation
Reviewer's Guide by SourceryThis pull request fixes the passing of the context argument to the is_observed method in various constraint-related files. The main changes involve removing the context from the ConstraintVerification constructor and passing it directly to the is_observed method instead. File-Level Changes
Tips
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @alimaktabi - I've reviewed your changes - here's some feedback:
Overall Comments:
- Consider removing the unused 'context' parameter from the constructor calls where it's still present, such as in tokenTap/validators.py.
- The change to pass context to is_observed() instead of storing it in the object is good, but it might be worth creating a separate task to ensure this pattern is consistently applied throughout the codebase.
Here's what I looked at during the review
- 🟡 General issues: 1 issue found
- 🟢 Security: all looks good
- 🟢 Testing: all looks good
- 🟡 Complexity: 1 issue found
- 🟢 Documentation: all looks good
Help me be more useful! Please click 👍 or 👎 on each comment to tell me if it was helpful.
core/constraints/captcha.py
Outdated
if self.context is None or self.context.get("requset") is None: | ||
context = kwargs.get("context") | ||
|
||
if context is None or context.get("requset") is None: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
issue (typo): Fix typo in 'requset'
The word 'request' is misspelled as 'requset' here and in the line below. This typo could cause issues with accessing the correct data.
@@ -16,17 +16,19 @@ class HasVerifiedCloudflareCaptcha(ConstraintVerification): | |||
|
|||
def is_observed(self, *args, **kwargs) -> bool: | |||
|
|||
if self.context is None or self.context.get("requset") is None: | |||
context = kwargs.get("context") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
issue (complexity): Consider refactoring to use self.context directly.
The new code introduces unnecessary complexity by using kwargs
to extract context
, which is redundant since self.context
is already available. This adds an extra layer of indirection without clear benefits and can lead to inconsistencies, especially if the rest of the class relies on instance variables. Additionally, the code does not check if context
is provided in kwargs
, potentially leading to errors. Consider refactoring to maintain simplicity and consistency with the original design, using self.context
directly. This approach reduces complexity and aligns with object-oriented principles.
Summary by Sourcery
Fix the handling of the context argument in the is_observed method and enhance the verification process by including an IP address check.
Bug Fixes:
Enhancements: