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

chore: use isinstance() instead of type comparison #1792

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

parthea
Copy link
Contributor

@parthea parthea commented May 6, 2022

Fixes warning from flake8 . --select E721

(py39) partheniou@partheniou-vm-2:~/git/google-api-python-client$ flake8 . --select E721
./googleapiclient/model.py:177:28: E721 do not compare types, use 'isinstance()'
./googleapiclient/model.py:396:37: E721 do not compare types, use 'isinstance()'
./googleapiclient/discovery.py:701:24: E721 do not compare types, use 'isinstance()'
./googleapiclient/discovery.py:712:24: E721 do not compare types, use 'isinstance()'
./googleapiclient/discovery.py:1078:66: E721 do not compare types, use 'isinstance()'

@parthea parthea requested a review from a team as a code owner May 6, 2022 15:31
@product-auto-label product-auto-label bot added the size: s Pull request size is small. label May 6, 2022
@@ -698,21 +698,15 @@ def _cast(value, schema_type):
A string representation of 'value' based on the schema_type.
"""
if schema_type == "string":
if type(value) == type("") or type(value) == type(""):
Copy link

Choose a reason for hiding this comment

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

This looks weird, but also potentially unsafe to remove.

Copy link

Choose a reason for hiding this comment

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

This is indeed weird, but is also safe.

Look at the last time it was changed (you will have to expand discover.py and scroll to line 701): 3bbefc1#diff-b039ba2bb64e79cf4c77e4fe5a4b21a826172e8b7ae9be872fd2d46047c05cbbL695-R701

Originally, it was

if type(value) == type("") or type(value) == type(u""):

But was changed automatically to be

if type(value) == type("") or type(value) == type(""):

because type("") == type(u"") == "str".

This if is redundant and pretty silly, and should be changed, no?

@parthea parthea marked this pull request as draft January 8, 2024 17:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
size: s Pull request size is small.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants