Skip to content

Commit 4287af4

Browse files
authored
Renable flake8 warning about getattr with constant string (#6848)
1 parent 0983acf commit 4287af4

File tree

6 files changed

+10
-13
lines changed

6 files changed

+10
-13
lines changed

mypy/fscache.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -144,9 +144,7 @@ def _fake_init(self, path: str) -> os.stat_result:
144144
seq[stat.ST_NLINK] = 1
145145
seq[stat.ST_SIZE] = 0
146146
tpl = tuple(seq)
147-
# FIXME: this works around typeshed claiming stat_result is from posix
148-
# (typeshed #2683)
149-
st = getattr(os, 'stat_result')(tpl)
147+
st = os.stat_result(tpl)
150148
self.stat_cache[path] = st
151149
# Make listdir() and read() also pretend this file exists.
152150
self.fake_package_cache.add(dirname)

mypy/main.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -679,7 +679,7 @@ def add_invertible_flag(flag: str,
679679

680680
# Set strict flags before parsing (if strict mode enabled), so other command
681681
# line options can override.
682-
if getattr(dummy, 'special-opts:strict'):
682+
if getattr(dummy, 'special-opts:strict'): # noqa
683683
for dest, value in strict_flag_assignments:
684684
setattr(options, dest, value)
685685

mypy/messages.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1396,7 +1396,7 @@ def [T <: int] f(self, x: int, y: T) -> None
13961396

13971397
# If we got a "special arg" (i.e: self, cls, etc...), prepend it to the arg list
13981398
if tp.definition is not None and tp.definition.name() is not None:
1399-
definition_args = getattr(tp.definition, 'arg_names')
1399+
definition_args = tp.definition.arg_names # type: ignore
14001400
if definition_args and tp.arg_names != definition_args \
14011401
and len(definition_args) > 0:
14021402
if s:

mypy/server/objgraph.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,11 +78,11 @@ def get_edges(o: object) -> Iterator[Tuple[object, object]]:
7878
# in closures and self pointers to other objects
7979

8080
if hasattr(e, '__closure__'):
81-
yield (s, '__closure__'), getattr(e, '__closure__')
81+
yield (s, '__closure__'), e.__closure__ # type: ignore
8282
if hasattr(e, '__self__'):
83-
se = getattr(e, '__self__')
83+
se = e.__self__ # type: ignore
8484
if se is not o and se is not type(o):
85-
yield (s, '__self__'), se
85+
yield s.__self__, se # type: ignore
8686
else:
8787
if not type(e) in TYPE_BLACKLIST:
8888
yield s, e

mypy/stubgenc.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,8 @@ def is_c_property(obj: object) -> bool:
112112
return inspect.isdatadescriptor(obj) and hasattr(obj, 'fget')
113113

114114

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

118118

119119
def is_c_type(obj: object) -> bool:
@@ -243,7 +243,7 @@ def generate_c_type_stub(module: ModuleType,
243243
"""
244244
# typeshed gives obj.__dict__ the not quite correct type Dict[str, Any]
245245
# (it could be a mappingproxy!), which makes mypyc mad, so obfuscate it.
246-
obj_dict = getattr(obj, '__dict__') # type: Mapping[str, Any]
246+
obj_dict = getattr(obj, '__dict__') # type: Mapping[str, Any] # noqa
247247
items = sorted(obj_dict.items(), key=lambda x: method_name_sort_key(x[0]))
248248
methods = [] # type: List[str]
249249
properties = [] # type: List[str]

setup.cfg

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,7 @@ exclude =
4444
# B006: use of mutable defaults in function signatures
4545
# B007: Loop control variable not used within the loop body.
4646
# B011: Don't use assert False
47-
# B009: Don't use getattr with constant strings (FIXME)
48-
ignore = E251,E128,F401,W601,E701,W503,W504,E704,E402,B3,B006,B007,B011,B009
47+
ignore = E251,E128,F401,W601,E701,W503,W504,E704,E402,B3,B006,B007,B011
4948

5049
[coverage:run]
5150
branch = true

0 commit comments

Comments
 (0)