Skip to content

Commit

Permalink
Renable flake8 warning about getattr with constant string (#6848)
Browse files Browse the repository at this point in the history
  • Loading branch information
msullivan authored May 20, 2019
1 parent 0983acf commit 4287af4
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 13 deletions.
4 changes: 1 addition & 3 deletions mypy/fscache.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,9 +144,7 @@ def _fake_init(self, path: str) -> os.stat_result:
seq[stat.ST_NLINK] = 1
seq[stat.ST_SIZE] = 0
tpl = tuple(seq)
# FIXME: this works around typeshed claiming stat_result is from posix
# (typeshed #2683)
st = getattr(os, 'stat_result')(tpl)
st = os.stat_result(tpl)
self.stat_cache[path] = st
# Make listdir() and read() also pretend this file exists.
self.fake_package_cache.add(dirname)
Expand Down
2 changes: 1 addition & 1 deletion mypy/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -679,7 +679,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
for dest, value in strict_flag_assignments:
setattr(options, dest, value)

Expand Down
2 changes: 1 addition & 1 deletion mypy/messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -1396,7 +1396,7 @@ def [T <: int] f(self, x: int, y: T) -> None

# If we got a "special arg" (i.e: self, cls, etc...), prepend it to the arg list
if tp.definition is not None and tp.definition.name() is not None:
definition_args = getattr(tp.definition, 'arg_names')
definition_args = tp.definition.arg_names # type: ignore
if definition_args and tp.arg_names != definition_args \
and len(definition_args) > 0:
if s:
Expand Down
6 changes: 3 additions & 3 deletions mypy/server/objgraph.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
if hasattr(e, '__self__'):
se = getattr(e, '__self__')
se = e.__self__ # type: ignore
if se is not o and se is not type(o):
yield (s, '__self__'), se
yield s.__self__, se # type: ignore
else:
if not type(e) in TYPE_BLACKLIST:
yield s, e
Expand Down
6 changes: 3 additions & 3 deletions mypy/stubgenc.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,8 @@ def is_c_property(obj: object) -> bool:
return inspect.isdatadescriptor(obj) and hasattr(obj, 'fget')


def is_c_property_readonly(prop: object) -> bool:
return getattr(prop, 'fset') is None
def is_c_property_readonly(prop: Any) -> bool:
return prop.fset is None


def is_c_type(obj: object) -> bool:
Expand Down Expand Up @@ -243,7 +243,7 @@ def generate_c_type_stub(module: ModuleType,
"""
# typeshed gives obj.__dict__ the not quite correct type Dict[str, Any]
# (it could be a mappingproxy!), which makes mypyc mad, so obfuscate it.
obj_dict = getattr(obj, '__dict__') # type: Mapping[str, Any]
obj_dict = getattr(obj, '__dict__') # type: Mapping[str, Any] # noqa
items = sorted(obj_dict.items(), key=lambda x: method_name_sort_key(x[0]))
methods = [] # type: List[str]
properties = [] # type: List[str]
Expand Down
3 changes: 1 addition & 2 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,7 @@ exclude =
# B006: use of mutable defaults in function signatures
# B007: Loop control variable not used within the loop body.
# B011: Don't use assert False
# B009: Don't use getattr with constant strings (FIXME)
ignore = E251,E128,F401,W601,E701,W503,W504,E704,E402,B3,B006,B007,B011,B009
ignore = E251,E128,F401,W601,E701,W503,W504,E704,E402,B3,B006,B007,B011

[coverage:run]
branch = true
Expand Down

0 comments on commit 4287af4

Please sign in to comment.