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

Fix type comparisons #1382

Merged
merged 2 commits into from
Aug 7, 2023
Merged

Conversation

bernt-matthias
Copy link
Contributor

linter complained about this over here #1381

Not sure if isinstance or is is correct?

linter complained about this over here galaxyproject#1381
@@ -191,12 +191,12 @@ def _lint_best_practices(path: str, lint_context: WorkflowLintContext) -> None:
"""

def check_json_for_untyped_params(j):
values = j if type(j) == list else j.values()
values = j if isinstance(j, list) else j.values()
Copy link
Member

Choose a reason for hiding this comment

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

Can you check this is a dict instance instead ? that should be less narrow. Also the check in line 196 isn't really how you'd do this

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Can you check this is a dict instance instead ?

So is TYPE everywhere?

Also the check in line 196 isn't really how you'd do this

Also with is?

Copy link
Member

Choose a reason for hiding this comment

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

No, type is type is the most narrow of them all which will not work for any subclasses. .values() will only work for objects that satisfy Mapping, while any j that is Iterable will work. So check for the specific instance where you need to call .values() first isinstance(j, Mapping) and don't worry about the other types that will all be fine.

Copy link
Member

@mvdbeek mvdbeek 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!

@mvdbeek mvdbeek merged commit 51c7be5 into galaxyproject:master Aug 7, 2023
11 of 14 checks passed
@mvdbeek mvdbeek changed the title fix type comparisons Fix type comparisons Sep 1, 2023
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.

2 participants