DiCE icon indicating copy to clipboard operation
DiCE copied to clipboard

Fix to unify type comparison methods

Open daikikatsuragawa opened this issue 3 years ago • 6 comments

This is a modification to unify the type comparison method.

Previously, there were two methods

  • if type(ABC) is str:
  • if isinstance(ABC, str):

This fix is related to coding and does not affect services. However, this unification is expected to increase code maintainability during development.

Use isinstance() rather than type() for a typecheck. reference : https://pycodequ.al/docs/pylint-messages/c0123-unidiomatic-typecheck.html

daikikatsuragawa avatar Jun 21 '22 18:06 daikikatsuragawa

@daikikatsuragawa Thanks for the PR. Could you add a flake8 rule to test for the above as per https://www.flake8rules.com/rules/E721.html? It will be useful for future that we don't add class checks with type. What do you think?

gaugup avatar Jun 24 '22 11:06 gaugup

@gaugup

Could you add a flake8 rule to test for the above as per https://www.flake8rules.com/rules/E721.html? It will be useful for future that we don't add class checks with type. What do you think?

Thank you. I will add it. Also, I will fix the failing CI.

daikikatsuragawa avatar Jun 28 '22 13:06 daikikatsuragawa

I will fix the failing CI.

This one has been corrected. https://github.com/interpretml/DiCE/pull/311/commits/bb43f483b0ffba57568f9c3255b2b6a4b39f6560

daikikatsuragawa avatar Jun 28 '22 14:06 daikikatsuragawa

@gaugup

Could you add a flake8 rule to test for the above as per https://www.flake8rules.com/rules/E721.html? It will be useful for future that we don't add class checks with type. What do you think?

I was considering adding the following.

https://github.com/interpretml/DiCE/blob/ea6f48472054bd48ec673c1fa1e6bd60ab5a4bef/.github/workflows/python-linting.yml#L32

I tried the following locally, added the error code, and verified that it did not seem to be working properly.

$ flake8 . --count --select=E721,E9,F63,F7,F82 --show-source --statistics

What is it, do you know? 🤔

daikikatsuragawa avatar Jun 28 '22 14:06 daikikatsuragawa

I tried the following locally, added the error code, and verified that it did not seem to be working properly.

$ flake8 . --count --select=E721,E9,F63,F7,F82 --show-source --statistics

What is it, do you know? 🤔

Ah, do you mean that the flake8 still passes when type is used in the code?

amit-sharma avatar Jul 11 '22 04:07 amit-sharma

Yes, that's right.

daikikatsuragawa avatar Jul 11 '22 12:07 daikikatsuragawa