@@ -59,14 +59,12 @@ class AttrCleaner:
59
59
on attribute lookup."""
60
60
61
61
def __init__ (self , obj : Any ) -> None :
62
- self .obj = obj
62
+ self ._obj = obj
63
63
64
64
def __enter__ (self ) -> None :
65
65
"""Try to make an object not exhibit side-effects on attribute
66
66
lookup."""
67
- type_ = type (self .obj )
68
- __getattribute__ = None
69
- __getattr__ = None
67
+ type_ = type (self ._obj )
70
68
# Dark magic:
71
69
# If __getattribute__ doesn't exist on the class and __getattr__ does
72
70
# then __getattr__ will be called when doing
@@ -89,7 +87,7 @@ def __enter__(self) -> None:
89
87
except TypeError :
90
88
# XXX: This happens for e.g. built-in types
91
89
__getattribute__ = None
92
- self .attribs = (__getattribute__ , __getattr__ )
90
+ self ._attribs = (__getattribute__ , __getattr__ )
93
91
# /Dark magic
94
92
95
93
def __exit__ (
@@ -99,8 +97,8 @@ def __exit__(
99
97
exc_tb : Optional [TracebackType ],
100
98
) -> Literal [False ]:
101
99
"""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
104
102
# Dark magic:
105
103
if __getattribute__ is not None :
106
104
setattr (type_ , "__getattribute__" , __getattribute__ )
@@ -329,13 +327,13 @@ def _get_argspec_from_signature(f: Callable) -> ArgSpec:
329
327
)
330
328
331
329
332
- get_encoding_line_re = LazyReCompile (r"^.*coding[:=]\s*([-\w.]+).*$" )
330
+ _get_encoding_line_re = LazyReCompile (r"^.*coding[:=]\s*([-\w.]+).*$" )
333
331
334
332
335
333
def get_encoding (obj ) -> str :
336
334
"""Try to obtain encoding information of the source of an object."""
337
335
for line in inspect .findsource (obj )[0 ][:2 ]:
338
- m = get_encoding_line_re .search (line )
336
+ m = _get_encoding_line_re .search (line )
339
337
if m :
340
338
return m .group (1 )
341
339
return "utf8"
@@ -344,9 +342,9 @@ def get_encoding(obj) -> str:
344
342
def get_encoding_file (fname : str ) -> str :
345
343
"""Try to obtain encoding information from a Python source file."""
346
344
with open (fname , encoding = "ascii" , errors = "ignore" ) as f :
347
- for unused in range (2 ):
345
+ for _ in range (2 ):
348
346
line = f .readline ()
349
- match = get_encoding_line_re .search (line )
347
+ match = _get_encoding_line_re .search (line )
350
348
if match :
351
349
return match .group (1 )
352
350
return "utf8"
0 commit comments