@@ -559,14 +559,14 @@ def query_devices(device=None, kind=None):
559559
560560 """
561561 if kind not in ('input' , 'output' , None ):
562- raise ValueError ('Invalid kind: {0 !r}' .format (kind ))
562+ raise ValueError ('Invalid kind: {!r}' .format (kind ))
563563 if device is None and kind is None :
564564 return DeviceList (query_devices (i )
565565 for i in range (_check (_lib .Pa_GetDeviceCount ())))
566566 device = _get_device_id (device , kind , raise_on_error = True )
567567 info = _lib .Pa_GetDeviceInfo (device )
568568 if not info :
569- raise PortAudioError ('Error querying device {0 }' .format (device ))
569+ raise PortAudioError ('Error querying device {}' .format (device ))
570570 assert info .structVersion == 2
571571 name_bytes = _ffi .string (info .name )
572572 try :
@@ -596,7 +596,7 @@ def query_devices(device=None, kind=None):
596596 }
597597 if kind and device_dict ['max_' + kind + '_channels' ] < 1 :
598598 raise ValueError (
599- 'Not an {0 } device: {1 !r}' .format (kind , device_dict ['name' ]))
599+ 'Not an {} device: {!r}' .format (kind , device_dict ['name' ]))
600600 return device_dict
601601
602602
@@ -642,7 +642,7 @@ def query_hostapis(index=None):
642642 for i in range (_check (_lib .Pa_GetHostApiCount ())))
643643 info = _lib .Pa_GetHostApiInfo (index )
644644 if not info :
645- raise PortAudioError ('Error querying host API {0 }' .format (index ))
645+ raise PortAudioError ('Error querying host API {}' .format (index ))
646646 assert info .structVersion == 1
647647 return {
648648 'name' : _ffi .string (info .name ).decode (),
@@ -858,7 +858,7 @@ def callback_ptr(iptr, optr, frames, time, status, _):
858858 _check (_lib .Pa_OpenStream (self ._ptr , iparameters , oparameters ,
859859 samplerate , blocksize , stream_flags ,
860860 callback_ptr , userdata ),
861- 'Error opening {0 }' .format (self .__class__ .__name__ ))
861+ 'Error opening {}' .format (self .__class__ .__name__ ))
862862
863863 # dereference PaStream** --> PaStream*
864864 self ._ptr = self ._ptr [0 ]
@@ -1493,7 +1493,7 @@ def write(self, data):
14931493 if data .ndim > 1 and data .shape [1 ] != channels :
14941494 raise ValueError ('Number of channels must match' )
14951495 if data .dtype != dtype :
1496- raise TypeError ('dtype mismatch: {0 !r} vs {1 !r}' .format (
1496+ raise TypeError ('dtype mismatch: {!r} vs {!r}' .format (
14971497 data .dtype .name , dtype ))
14981498 if not data .flags .c_contiguous :
14991499 raise TypeError ('data must be C-contiguous' )
@@ -1776,8 +1776,6 @@ def __repr__(self):
17761776 ins = info ['max_input_channels' ],
17771777 outs = info ['max_output_channels' ])
17781778 for idx , info in enumerate (self ))
1779- if _sys .version_info .major < 3 :
1780- return text .encode (_sys .stdout .encoding or 'utf-8' , 'replace' )
17811779 return text
17821780
17831781
@@ -1812,7 +1810,7 @@ def __repr__(self):
18121810 flags = str (self )
18131811 if not flags :
18141812 flags = 'no flags set'
1815- return '<sounddevice.CallbackFlags: {0 }>' .format (flags )
1813+ return '<sounddevice.CallbackFlags: {}>' .format (flags )
18161814
18171815 def __str__ (self ):
18181816 return ', ' .join (name .replace ('_' , ' ' ) for name in dir (self )
@@ -1821,8 +1819,6 @@ def __str__(self):
18211819 def __bool__ (self ):
18221820 return bool (self ._flags )
18231821
1824- __nonzero__ = __bool__ # For Python 2.x
1825-
18261822 def __ior__ (self , other ):
18271823 if not isinstance (other , CallbackFlags ):
18281824 return NotImplemented
@@ -2141,11 +2137,11 @@ class PortAudioError(Exception):
21412137 def __str__ (self ):
21422138 errormsg = self .args [0 ] if self .args else ''
21432139 if len (self .args ) > 1 :
2144- errormsg = '{0 } [PaErrorCode {1 }]' .format (errormsg , self .args [1 ])
2140+ errormsg = '{} [PaErrorCode {}]' .format (errormsg , self .args [1 ])
21452141 if len (self .args ) > 2 :
21462142 host_api , hosterror_code , hosterror_text = self .args [2 ]
21472143 hostname = query_hostapis (host_api )['name' ]
2148- errormsg = "{0 }: '{1 }' [{2 } error {3 }]" .format (
2144+ errormsg = "{}: '{}' [{} error {}]" .format (
21492145 errormsg , hosterror_text , hostname , hosterror_code )
21502146
21512147 return errormsg
@@ -2637,7 +2633,7 @@ def _check(err, msg=''):
26372633
26382634 errormsg = _ffi .string (_lib .Pa_GetErrorText (err )).decode ()
26392635 if msg :
2640- errormsg = '{0 }: {1 }' .format (msg , errormsg )
2636+ errormsg = '{}: {}' .format (msg , errormsg )
26412637
26422638 if err == _lib .paUnanticipatedHostError :
26432639 # (gh82) We grab the host error info here rather than inside
@@ -2669,7 +2665,7 @@ def _get_device_id(id_or_query_string, kind, raise_on_error=False):
26692665 if idev == odev :
26702666 id_or_query_string = idev
26712667 else :
2672- raise ValueError ('Input and output device are different: {0 !r}'
2668+ raise ValueError ('Input and output device are different: {!r}'
26732669 .format (id_or_query_string ))
26742670
26752671 if isinstance (id_or_query_string , int ):
@@ -2712,7 +2708,7 @@ def _get_device_id(id_or_query_string, kind, raise_on_error=False):
27122708 if raise_on_error :
27132709 raise ValueError ('Multiple ' + kind + ' devices found for ' +
27142710 repr (id_or_query_string ) + ':\n ' +
2715- '\n ' .join ('[{0 }] {1 }' .format (id , name )
2711+ '\n ' .join ('[{}] {}' .format (id , name )
27162712 for id , name in matches ))
27172713 else :
27182714 return - 1
0 commit comments