pycodestyle icon indicating copy to clipboard operation
pycodestyle copied to clipboard

E721: Naive for modules named `types`

Open coxley opened this issue 6 years ago • 6 comments

This relates to #671

Install Method and Version

pip install --user pycodestyle
pycodestyle --version
2.4.0

Context

E721 is the error for comparing the type(x) of something with another instead of using isinstance. Looking at #671, I thought this was something that I could submit a PR for. Looking at the testsuite for E72, however, this is expected behavior currently.

Problem

Any object named types is assumed to be the stdlib types module. There are many just reasons for a library to have a types module making selective disabling of E721 mandatory. (or alias imports).


from foo import types

some_value = get_column_from_db()
if some_value == types.MyThing.SOME_PROPERTY:
    ...

Submitting an issue instead of PR because I'm not sure what context can be available to checks. :) The goal of the project is to be quick so the ast is out of the question. With that, either:

  • The scope of the check should be reduced to not include types module checking
    • If we can't do it right, we shouldn't settle for "good enough" for an E-level check
  • Regex could be expanded to include known contents of types
    • This still seems off because more maintenance

coxley avatar Jan 27 '19 01:01 coxley