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

Renable flake8 warning about getattr with constant string #6848

Merged
merged 2 commits into from
May 20, 2019

Conversation

msullivan
Copy link
Collaborator

Most of the getattr calls with constant strings were to shut up mypy, so add a bunch of
# type: ignores for those.

A couple were for other things (something dumb with mypyc, using an invalid identifier),
so those get # noqa.

Not totally sure if this is actually better, which is why I didn't put the PR up when I first wrote it,
but pushing now to see what other people think so I can clean up the branch.
(I'm leaning towards it being better, but only marginally.)

mypy/fscache.py Outdated
@@ -146,7 +146,7 @@ def _fake_init(self, path: str) -> os.stat_result:
tpl = tuple(seq)
# FIXME: this works around typeshed claiming stat_result is from posix
# (typeshed #2683)
st = getattr(os, 'stat_result')(tpl)
st = getattr(os, 'stat_result')(tpl) # noqa
Copy link
Member

Choose a reason for hiding this comment

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

python/typeshed#2683 was merged, so seems like this can just use os.stat_result?

In general I would have preferred for this to use # type: ignore, which is more greppable, and that way a run with --warn-unused-ignores could have found that this hack is no longer needed.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Fixed. It was working around an issue that showed up in mypyc, not in mypy, so the getattr was needed for annoying reasons.

@msullivan msullivan requested a review from gvanrossum May 20, 2019 18:27
Copy link
Member

@gvanrossum gvanrossum left a comment

Choose a reason for hiding this comment

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

Great!

@@ -700,7 +700,7 @@ def add_invertible_flag(flag: str,

# Set strict flags before parsing (if strict mode enabled), so other command
# line options can override.
if getattr(dummy, 'special-opts:strict'):
if getattr(dummy, 'special-opts:strict'): # noqa
Copy link
Member

Choose a reason for hiding this comment

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

Curious that this requires a # noqa -- apparently flake8 doesn't realize that the literal string is not a valid identifier. :-)

@msullivan msullivan merged commit 4287af4 into master May 20, 2019
@msullivan msullivan deleted the flake8-getattr branch May 20, 2019 19:40
Copy link
Member

@JelleZijlstra JelleZijlstra left a comment

Choose a reason for hiding this comment

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

I forgot to hit "Submit" for this, sorry.

@@ -78,11 +78,11 @@ def get_edges(o: object) -> Iterator[Tuple[object, object]]:
# in closures and self pointers to other objects

if hasattr(e, '__closure__'):
yield (s, '__closure__'), getattr(e, '__closure__')
yield (s, '__closure__'), e.__closure__ # type: ignore
Copy link
Member

Choose a reason for hiding this comment

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

also s.__closure__?

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.

3 participants