Pycodestyle: E721: Naive for modules named `types`

Created on 27 Jan 2019  路  5Comments  路  Source: PyCQA/pycodestyle

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

All 5 comments

@froody: is this fixed and deployed in a recent release?

@coxley no, the PR which mentioned this was closed without merge

Ah whoops, missed that. Thanks.

Ping ping ping. We run into so many false-positives with this. Considering disabling the lint globally in our setup, but it's a nice one to have.

@coxley please don't ping issues like that, I'd suggest attempting a patch

Was this page helpful?
0 / 5 - 0 ratings