Skip to content

Commit 0b4b7c3

Browse files
committed
Merge pull request #76 from bastibe/repr
OK, I'm merging this. > I don't see why we need `format` should require `subtype` and `endian`, but if you insist on it, we'll do it that way. I'd rather have always too much information than a different amount of information for different files. If we get annoyed by the large amount of information, we can still remove the `format`/`subtype`/`endian` triple at a later point. Also, let's see if the implementation of #58 sheds a different light on this.
2 parents ee7c34d + 5e9a075 commit 0b4b7c3

File tree

2 files changed

+9
-7
lines changed

2 files changed

+9
-7
lines changed

pysoundfile.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -638,10 +638,10 @@ def __init__(self, file, mode='r', samplerate=None, channels=None,
638638
mode_int = _snd.SFM_WRITE
639639

640640
old_fmt = format
641-
self._name = getattr(file, 'name', file)
641+
self._name = file
642642
if format is None:
643-
format = str(self.name).rsplit('.', 1)[-1].upper()
644-
if format not in _formats and 'r' not in modes:
643+
format = str(getattr(file, 'name', file)).rsplit('.', 1)[-1]
644+
if format.upper() not in _formats and 'r' not in modes:
645645
raise TypeError(
646646
"No format specified and unable to get format from "
647647
"file extension: %s" % repr(self.name))
@@ -720,9 +720,10 @@ def __init__(self, file, mode='r', samplerate=None, channels=None,
720720
_file = None
721721

722722
def __repr__(self):
723-
return ('SoundFile("{}", mode="{}", samplerate={}, channels={}, '
724-
'format="{}")').format(self.name, self.mode, self.samplerate,
725-
self.channels, self.format)
723+
return ('SoundFile(%r, mode=%r, samplerate=%i, channels=%i, '
724+
'format=%r, subtype=%r, endian=%r)' %
725+
(self.name, self.mode, self.samplerate, self.channels,
726+
self.format, self.subtype, self.endian))
726727

727728
def __del__(self):
728729
self.close()

tests/test_pysoundfile.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -455,7 +455,8 @@ def test__repr__(sf_stereo_r):
455455
if not isinstance(sf_stereo_r.name, int):
456456
assert repr(sf_stereo_r) == ('SoundFile("{}", mode="r", '
457457
'samplerate=44100, channels=2, '
458-
'format="WAV")').format(filename_stereo)
458+
'format="WAV", subtype="FLOAT", '
459+
'endian="FILE")').format(filename_stereo)
459460

460461
def test_mode_should_be_in_write_mode(sf_stereo_w):
461462
assert sf_stereo_w.mode == 'w'

0 commit comments

Comments
 (0)