Skip to content

Commit

Permalink
remove metaclass check for protected access in properties
Browse files Browse the repository at this point in the history
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?..
  • Loading branch information
temyurchenko committed Sep 25, 2024
1 parent 88e4bc6 commit 4f936d3
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 22 deletions.
9 changes: 2 additions & 7 deletions pylint/checkers/classes/class_checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -470,13 +470,8 @@ def _is_attribute_property(name: str, klass: nodes.ClassDef) -> bool:
inferred
):
return True
if inferred.pytype() != property_name:
continue

cls = node_frame_class(inferred)
if cls == klass.declared_metaclass():
continue
return True
if inferred.pytype() == property_name:
return True
return False


Expand Down
12 changes: 0 additions & 12 deletions tests/functional/p/protected_access.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,6 @@ def __init__(self):
OBJ._teta # [protected-access]


# Make sure protect-access doesn't raise an exception Uninferable attributes
class MC:
@property
def nargs(self):
return 1 if self._nargs else 2


class Application(metaclass=MC):
def __no_special__(cls):
nargs = obj._nargs # [protected-access]


class Light:
@property
def _light_internal(self) -> None:
Expand Down
5 changes: 2 additions & 3 deletions tests/functional/p/protected_access.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
protected-access:19:0:19:9::Access to a protected member _teta of a client class:UNDEFINED
protected-access:31:16:31:26:Application.__no_special__:Access to a protected member _nargs of a client class:UNDEFINED
protected-access:41:14:41:35:Light.func:Access to a protected member _light_internal of a client class:UNDEFINED
protected-access:45:10:45:31:func:Access to a protected member _light_internal of a client class:UNDEFINED
protected-access:29:14:29:35:Light.func:Access to a protected member _light_internal of a client class:UNDEFINED
protected-access:33:10:33:31:func:Access to a protected member _light_internal of a client class:UNDEFINED

0 comments on commit 4f936d3

Please sign in to comment.