Skip to content

Commit 846b127

Browse files
barneygaleencukou
andauthored
Apply suggestions from code review
Co-authored-by: Petr Viktorin <[email protected]>
1 parent 0c9d1bf commit 846b127

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

Lib/pathlib/_os.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -169,11 +169,11 @@ def copyfileobj(source_f, target_f):
169169
def _open_reader(obj):
170170
cls = type(obj)
171171
try:
172-
return cls.__open_reader__(obj)
172+
open_reader = cls.__open_reader__
173173
except AttributeError:
174-
if hasattr(cls, '__open_reader__'):
175-
raise
176-
raise TypeError(f"{cls.__name__} can't be opened for reading")
174+
raise TypeError(f"{cls.__name__} can't be opened for reading")
175+
else:
176+
return open_reader(obj)
177177

178178

179179
def _open_writer(obj, mode):
@@ -203,7 +203,7 @@ def vfsopen(obj, mode='r', buffering=-1, encoding=None, errors=None,
203203
the built-in open() function does.
204204
205205
Unlike the built-in open() function, this function accepts 'openable'
206-
objects, which are objects with any of these magic methods:
206+
objects, which are objects with any of these special methods:
207207
208208
__open_reader__()
209209
__open_writer__(mode)

0 commit comments

Comments
 (0)