Skip to content

Commit 5feface

Browse files
authored
remove metaclass check for protected access in properties (#9966)
1. it was incorrect when the property wasn't inside a class and the enclosing class didn't have an explicit metaclass 2. The conjugated test is full with errors and I can't understand the intention. (the errors: `MC` doesn't inherit `type`; `_nargs` isn't defined; `obj` isn't defined, etc). What is the pointed of testing protected access on an undefined variable?.. (See full discussions on the MR for reasoning)
1 parent 0d7b0d7 commit 5feface

File tree

3 files changed

+4
-22
lines changed

3 files changed

+4
-22
lines changed

pylint/checkers/classes/class_checker.py

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -470,13 +470,8 @@ def _is_attribute_property(name: str, klass: nodes.ClassDef) -> bool:
470470
inferred
471471
):
472472
return True
473-
if inferred.pytype() != property_name:
474-
continue
475-
476-
cls = node_frame_class(inferred)
477-
if cls == klass.declared_metaclass():
478-
continue
479-
return True
473+
if inferred.pytype() == property_name:
474+
return True
480475
return False
481476

482477

tests/functional/p/protected_access.py

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,18 +19,6 @@ def __init__(self):
1919
OBJ._teta # [protected-access]
2020

2121

22-
# Make sure protect-access doesn't raise an exception Uninferable attributes
23-
class MC:
24-
@property
25-
def nargs(self):
26-
return 1 if self._nargs else 2
27-
28-
29-
class Application(metaclass=MC):
30-
def __no_special__(cls):
31-
nargs = obj._nargs # [protected-access]
32-
33-
3422
class Light:
3523
@property
3624
def _light_internal(self) -> None:
Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
protected-access:19:0:19:9::Access to a protected member _teta of a client class:UNDEFINED
2-
protected-access:31:16:31:26:Application.__no_special__:Access to a protected member _nargs of a client class:UNDEFINED
3-
protected-access:41:14:41:35:Light.func:Access to a protected member _light_internal of a client class:UNDEFINED
4-
protected-access:45:10:45:31:func:Access to a protected member _light_internal of a client class:UNDEFINED
2+
protected-access:29:14:29:35:Light.func:Access to a protected member _light_internal of a client class:UNDEFINED
3+
protected-access:33:10:33:31:func:Access to a protected member _light_internal of a client class:UNDEFINED

0 commit comments

Comments
 (0)