Skip to content

Conversation

@RGAlexander216
Copy link

@RGAlexander216 RGAlexander216 commented Jun 9, 2025

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)

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.
@RGAlexander216 RGAlexander216 marked this pull request as ready for review June 9, 2025 19:55
Copilot AI review requested due to automatic review settings June 9, 2025 19:55

This comment was marked as outdated.

Changed type(variable) == int/str to use builtin isinstance(variable, int/str)
Changed type(backoff) == int to builtin isinstance(backoff, int).
@RGAlexander216 RGAlexander216 changed the title Fix moveToFailed list to integer comparison error. Python: Fix moveToFailed list to integer comparison error. Jun 9, 2025
Added secondary handle for when code is an integer.
@RGAlexander216 RGAlexander216 requested a review from Copilot June 9, 2025 20:08

This comment was marked as outdated.

@RGAlexander216 RGAlexander216 changed the title Python: Fix moveToFailed list to integer comparison error. fix(job.py): Fix Python moveToFailed list to integer comparison error. Jun 9, 2025
@RGAlexander216 RGAlexander216 changed the title fix(job.py): Fix Python moveToFailed list to integer comparison error. fix(job): Fix Python moveToFailed list to integer comparison error. Jun 10, 2025
@RGAlexander216
Copy link
Author

@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?

@roggervalf
Copy link
Collaborator

@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

@RGAlexander216
Copy link
Author

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.?

@roggervalf
Copy link
Collaborator

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

@RGAlexander216
Copy link
Author

RGAlexander216 commented Jun 13, 2025

@roggervalf

  • GitHub Copilot says that the OSV-Scanner failed likely due to dependency vulnerabilities. I didn't modify any libraries in my P.R., so that is a pre-existing issue and I believe could be the root of two of the three tests that failed.
  • The test of dragonflydb@latest is failing due to what boils down to a comparison in one of the lua scripts that Python's interpreter will handle silently, but is technically incorrect. It's comparing a variable of type boolean to an integer. Python's interpreter will just treat a boolean as a 1 or 0 in this comparison and this particular script is not a part of my P.R., so that is how it is written in the current release.
  • The test of redis@7-alpine is failing due to a 503 service unavailable error when trying to run a function/method named getCacheEntry, which is also causing a timeout issue downstream in the pytest run. This is also not a part of my P.R., so it is a part of the current release.

@RGAlexander216
Copy link
Author

@roggervalf Following up on this. To reiterate, the code modifications I made are not related to the conflicts.

@RGAlexander216 RGAlexander216 requested a review from Copilot June 26, 2025 15:10

This comment was marked as outdated.

RGAlexander216 and others added 2 commits June 26, 2025 10:19
This is an acceptable refactor.

Co-authored-by: Copilot <[email protected]>
@RGAlexander216 RGAlexander216 requested a review from Copilot June 26, 2025 15:25

This comment was marked as outdated.

@RGAlexander216 RGAlexander216 requested a review from Copilot June 26, 2025 22:58

This comment was marked as outdated.

Copy link
Author

@RGAlexander216 RGAlexander216 left a 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.

@manast manast requested a review from Copilot June 27, 2025 15:01
Copy link
Contributor

Copilot AI left a 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(...) == T checks with isinstance(...), excluding bool from int checks.
  • Update moveToFinished error handling to use isinstance and clarify comments.
  • Apply the same isinstance pattern 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 isinstance check (not the < 0 comparison) 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 getKeepJobs to verify behavior when shouldRemove is 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):

@manast
Copy link
Contributor

manast commented Jun 27, 2025

@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.

@RGAlexander216
Copy link
Author

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.

@RGAlexander216 RGAlexander216 changed the title fix(job): Fix Python moveToFailed list to integer comparison error. refactor(job): Implement isinstance(...) Python Function for Type Checking Jun 28, 2025
@RGAlexander216 RGAlexander216 changed the title refactor(job): Implement isinstance(...) Python Function for Type Checking refactor(job, scripts, backoff): Implement isinstance(...) Python Function for Type Checking Jun 28, 2025
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.

3 participants