Skip to content

Fix type comparisons#1382

Merged
mvdbeek merged 2 commits intogalaxyproject:masterfrom
bernt-matthias:type-comparisons
Aug 7, 2023
Merged

Fix type comparisons#1382
mvdbeek merged 2 commits intogalaxyproject:masterfrom
bernt-matthias:type-comparisons

Conversation

@bernt-matthias
Copy link
Collaborator

linter complained about this over here #1381

Not sure if isinstance or is is correct?

linter complained about this over here galaxyproject#1381

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