-
Notifications
You must be signed in to change notification settings - Fork 518
refactor(job, scripts, backoff): Implement isinstance(...) Python Function for Type Checking #3293
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
base: master
Are you sure you want to change the base?
Conversation
Use isinstance instead of type for type checking Fix failing if code < 0 check in moveToFailed method to check first element in the list. The variable code is a list, not an integer.
Added additional checks for the `code` variable to avoid potential IndexError and TypeError.
Changed type(variable) == int/str to use builtin isinstance(variable, int/str)
Changed type(backoff) == int to builtin isinstance(backoff, int).
Added secondary handle for when code is an integer.
Co-authored-by: Copilot <[email protected]>
Co-authored-by: Copilot <[email protected]>
|
@roggervalf, the test failures don't appear to be related to this P.R.. Is that an accurate assessment? Is the P.R. that you opened yesterday intended to address the underlying issues with the test failures? |
hi @RGAlexander216, yes this change is being covered in my pr |
@roggervalf, if your P.R. is merged, can the checks be retried for this P.R.? |
|
hey @RGAlexander216 seems like something is wrong in this pr, still failing in our tests. Btw once we release latest change you should be able to try it. Still we are working on fix our releases |
|
|
@roggervalf Following up on this. To reiterate, the code modifications I made are not related to the conflicts. |
This is an acceptable refactor. Co-authored-by: Copilot <[email protected]>
Co-authored-by: Copilot <[email protected]>
Acceptable Co-authored-by: Copilot <[email protected]>
Acceptable Co-authored-by: Copilot <[email protected]>
RGAlexander216
left a comment
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.
Revised with changes to reflect other changes that have been made since this P.R. was opened and resolved the conflicts.
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.
Pull Request Overview
This PR standardizes type checking by replacing type(x) == T with isinstance(x, T), adds explicit exclusion of bool where needed, and updates error handling for negative result codes in the moveToFinished script.
- Replace
type(...) == Tchecks withisinstance(...), excludingboolfromintchecks. - Update
moveToFinishederror handling to useisinstanceand clarify comments. - Apply the same
isinstancepattern to backoff normalization and job property assignments.
Reviewed Changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| python/bullmq/scripts.py | Swapped type(...) with isinstance(...), excluded bool in int checks, and updated comments in moveToFinished. |
| python/bullmq/job.py | Updated type checks for finished_on, delay, and returnvalue to use isinstance. |
| python/bullmq/backoffs.py | Changed backoff normalization to use isinstance for integer checks. |
Comments suppressed due to low confidence (2)
python/bullmq/scripts.py:636
- The comment is misleading: the
isinstancecheck (not the< 0comparison) excludes booleans. Consider rephrasing to something like:# Exclude bool from the int check because bool is a subclass of int in Python.
# result < 0 ensures that the value of result is not a Boolean.
python/bullmq/scripts.py:572
- [nitpick] Consider adding unit tests for
getKeepJobsto verify behavior whenshouldRemoveis a boolean, an integer, and a dict, ensuring the boolean exclusion and all branches work as intended.
if isinstance(shouldRemove, int) and not isinstance(shouldRemove, bool):
|
@RGAlexander216 Could you also add a test that fails without your fixes but passes with them? otherwise we cannot know if this really is fixing an issue or not. |
|
The original P.R.'s primary change was completely rewritten since this P.R. was opened. I unwittingly merged the current codebase yesterday overwriting the primary objective. However, the changes that are left do implement the "right" way to type check objects in Python. Otherwise there really isn't any purpose this P.R. anymore. |
Use isinstance instead of type for type checking
Why
Use Python's builtin isinstance instead of type for type checking.
How
Changed all type(variable) == str/int to isinstance(variable, str/int).
Additional Notes (Optional)