Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitfb923fd

Browse files
committed
Hide implementation details
1 parente59e924 commitfb923fd

File tree

1 file changed

+9
-11
lines changed

1 file changed

+9
-11
lines changed

‎bpython/inspection.py

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -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
exceptTypeError:
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__isnotNone:
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

335333
defget_encoding(obj)->str:
336334
"""Try to obtain encoding information of the source of an object."""
337335
forlineininspect.findsource(obj)[0][:2]:
338-
m=get_encoding_line_re.search(line)
336+
m=_get_encoding_line_re.search(line)
339337
ifm:
340338
returnm.group(1)
341339
return"utf8"
@@ -344,9 +342,9 @@ def get_encoding(obj) -> str:
344342
defget_encoding_file(fname:str)->str:
345343
"""Try to obtain encoding information from a Python source file."""
346344
withopen(fname,encoding="ascii",errors="ignore")asf:
347-
forunusedinrange(2):
345+
for_inrange(2):
348346
line=f.readline()
349-
match=get_encoding_line_re.search(line)
347+
match=_get_encoding_line_re.search(line)
350348
ifmatch:
351349
returnmatch.group(1)
352350
return"utf8"

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp