@@ -59,14 +59,12 @@ class AttrCleaner:
5959 on attribute lookup."""
6060
6161 def __init__ (self , obj : Any ) -> None :
62- self .obj = obj
62+ self ._obj = obj
6363
6464 def __enter__ (self ) -> None :
6565 """Try to make an object not exhibit side-effects on attribute
6666 lookup."""
67- type_ = type (self .obj )
68- __getattribute__ = None
69- __getattr__ = None
67+ type_ = type (self ._obj )
7068 # Dark magic:
7169 # If __getattribute__ doesn't exist on the class and __getattr__ does
7270 # then __getattr__ will be called when doing
@@ -89,7 +87,7 @@ def __enter__(self) -> None:
8987 except TypeError :
9088 # XXX: This happens for e.g. built-in types
9189 __getattribute__ = None
92- self .attribs = (__getattribute__ , __getattr__ )
90+ self ._attribs = (__getattribute__ , __getattr__ )
9391 # /Dark magic
9492
9593 def __exit__ (
@@ -99,8 +97,8 @@ def __exit__(
9997 exc_tb : Optional [TracebackType ],
10098 ) -> Literal [False ]:
10199 """Restore an object's magic methods."""
102- type_ = type (self .obj )
103- __getattribute__ , __getattr__ = self .attribs
100+ type_ = type (self ._obj )
101+ __getattribute__ , __getattr__ = self ._attribs
104102 # Dark magic:
105103 if __getattribute__ is not None :
106104 setattr (type_ , "__getattribute__" , __getattribute__ )
@@ -329,13 +327,13 @@ def _get_argspec_from_signature(f: Callable) -> ArgSpec:
329327 )
330328
331329
332- get_encoding_line_re = LazyReCompile (r"^.*coding[:=]\s*([-\w.]+).*$" )
330+ _get_encoding_line_re = LazyReCompile (r"^.*coding[:=]\s*([-\w.]+).*$" )
333331
334332
335333def get_encoding (obj ) -> str :
336334 """Try to obtain encoding information of the source of an object."""
337335 for line in inspect .findsource (obj )[0 ][:2 ]:
338- m = get_encoding_line_re .search (line )
336+ m = _get_encoding_line_re .search (line )
339337 if m :
340338 return m .group (1 )
341339 return "utf8"
@@ -344,9 +342,9 @@ def get_encoding(obj) -> str:
344342def get_encoding_file (fname : str ) -> str :
345343 """Try to obtain encoding information from a Python source file."""
346344 with open (fname , encoding = "ascii" , errors = "ignore" ) as f :
347- for unused in range (2 ):
345+ for _ in range (2 ):
348346 line = f .readline ()
349- match = get_encoding_line_re .search (line )
347+ match = _get_encoding_line_re .search (line )
350348 if match :
351349 return match .group (1 )
352350 return "utf8"
0 commit comments