Merge lp:~cjwatson/meliae/py3-duck-type-file into lp:meliae

Proposed by Colin Watson
Status: Merged
Approved by: John A Meinel
Approved revision: 223
Merged at revision: 224
Proposed branch: lp:~cjwatson/meliae/py3-duck-type-file
Merge into: lp:meliae
Diff against target: 20 lines (+6/-4)
1 file modified
meliae/loader.py (+6/-4)
To merge this branch: bzr merge lp:~cjwatson/meliae/py3-duck-type-file
Reviewer Review Type Date Requested Status
John A Meinel Approve
Review via email: mp+380583@code.launchpad.net

Commit message

Duck-type files in meliae.loader.load.

Description of the change

The "file" builtin doesn't exist on Python 3, but we really just need to know whether the source object has a "fileno" method, so test for that directly.

To post a comment you must log in.
Revision history for this message
John A Meinel (jameinel) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'meliae/loader.py'
2--- meliae/loader.py 2020-02-03 22:08:03 +0000
3+++ meliae/loader.py 2020-03-11 20:35:47 +0000
4@@ -528,10 +528,12 @@
5 cleanup = None
6 if isinstance(source, six.string_types):
7 source, cleanup = files.open_file(source)
8- if isinstance(source, file):
9- input_size = os.fstat(source.fileno()).st_size
10- else:
11- input_size = 0
12+ input_size = 0
13+ if hasattr(source, "fileno"):
14+ try:
15+ input_size = os.fstat(source.fileno()).st_size
16+ except OSError:
17+ pass
18 elif isinstance(source, (list, tuple)):
19 input_size = sum(map(len, source))
20 else:

Subscribers

People subscribed via source and target branches

to all changes: