-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
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
Conversation
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 |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this 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 |
There was a problem hiding this comment.
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. :-)
There was a problem hiding this 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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
also s.__closure__
?
Most of the
getattr
calls with constant strings were to shut up mypy, so add a bunch of# type: ignore
s 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.)