@@ -435,11 +435,11 @@ internal Exception UnsupportedOperationWithMessage(CodeContext/*!*/ context, str
435435 => PythonExceptions . CreateThrowable ( ( PythonType ) context . LanguageContext . GetModuleState ( _unsupportedOperationKey ) , msg ) ;
436436
437437 internal Exception AttributeError ( string attrName ) {
438- throw PythonOps . AttributeError ( "'{0}' object has no attribute '{1}'" , PythonOps . GetPythonTypeName ( this ) , attrName ) ;
438+ return PythonOps . AttributeError ( "'{0}' object has no attribute '{1}'" , PythonOps . GetPythonTypeName ( this ) , attrName ) ;
439439 }
440440
441441 internal Exception InvalidPosition ( BigInteger pos ) {
442- return PythonOps . IOError ( "Raw stream returned invalid position {0}" , pos ) ;
442+ return PythonOps . OSError ( "Raw stream returned invalid position {0}" , pos ) ;
443443 }
444444
445445 #endregion
@@ -550,7 +550,7 @@ public virtual BigInteger readinto(CodeContext/*!*/ context, object buf) {
550550 return data . Count ;
551551 }
552552
553- throw PythonOps . TypeError ( "must be read-write buffer, not " + PythonOps . GetPythonTypeName ( buf ) ) ;
553+ throw PythonOps . TypeError ( "must be read-write buffer, not {0}" , PythonOps . GetPythonTypeName ( buf ) ) ;
554554 }
555555
556556 public override BigInteger write ( CodeContext /*!*/ context , object buf ) {
@@ -648,11 +648,11 @@ public void __init__(
648648
649649 if ( _rawIO != null ) {
650650 if ( ! _rawIO . readable ( context ) ) {
651- throw PythonOps . IOError ( "\" raw\" argument must be readable." ) ;
651+ throw PythonOps . OSError ( "\" raw\" argument must be readable." ) ;
652652 }
653653 } else {
654654 if ( PythonOps . Not ( PythonOps . Invoke ( context , _raw , "readable" ) ) ) {
655- throw PythonOps . IOError ( "\" raw\" argument must be readable." ) ;
655+ throw PythonOps . OSError ( "\" raw\" argument must be readable." ) ;
656656 }
657657 }
658658 if ( buffer_size <= 0 ) {
@@ -1125,11 +1125,11 @@ public void __init__(
11251125 this . raw = raw ;
11261126 if ( _rawIO != null ) {
11271127 if ( ! _rawIO . writable ( context ) ) {
1128- throw PythonOps . IOError ( "\" raw\" argument must be writable." ) ;
1128+ throw PythonOps . OSError ( "\" raw\" argument must be writable." ) ;
11291129 }
11301130 } else {
11311131 if ( PythonOps . Not ( PythonOps . Invoke ( context , _raw , "writable" ) ) ) {
1132- throw PythonOps . IOError ( "\" raw\" argument must be writable." ) ;
1132+ throw PythonOps . OSError ( "\" raw\" argument must be writable." ) ;
11331133 }
11341134 }
11351135 if ( buffer_size <= 0 ) {
@@ -1332,7 +1332,7 @@ private void FlushNoLock(CodeContext/*!*/ context) {
13321332
13331333 int written = GetInt ( writtenObj , "write() should return integer" ) ;
13341334 if ( written > _writeBuf . Count || written < 0 ) {
1335- throw PythonOps . IOError ( "write() returned incorrect number of bytes" ) ;
1335+ throw PythonOps . OSError ( "write() returned incorrect number of bytes" ) ;
13361336 }
13371337 _writeBuf . RemoveRange ( 0 , written ) ;
13381338 count += written ;
@@ -1450,9 +1450,9 @@ public void __init__(
14501450 if ( buffer_size <= 0 ) {
14511451 throw PythonOps . ValueError ( "invalid buffer size (must be positive)" ) ;
14521452 } else if ( ! raw . readable ( context ) ) {
1453- throw PythonOps . IOError ( "\" raw\" argument must be readable." ) ;
1453+ throw PythonOps . OSError ( "\" raw\" argument must be readable." ) ;
14541454 } else if ( ! raw . writable ( context ) ) {
1455- throw PythonOps . IOError ( "\" raw\" argument must be writable." ) ;
1455+ throw PythonOps . OSError ( "\" raw\" argument must be writable." ) ;
14561456 }
14571457
14581458 _bufSize = buffer_size ;
@@ -1744,7 +1744,7 @@ private void FlushNoLock(CodeContext/*!*/ context) {
17441744 var bytes = Bytes . Make ( _writeBuf . ToArray ( ) ) ;
17451745 int written = ( int ) _inner . write ( context , bytes ) ;
17461746 if ( written > _writeBuf . Count || written < 0 ) {
1747- throw PythonOps . IOError ( "write() returned incorrect number of bytes" ) ;
1747+ throw PythonOps . OSError ( "write() returned incorrect number of bytes" ) ;
17481748 }
17491749 _writeBuf . RemoveRange ( 0 , written ) ;
17501750 count += written ;
@@ -1792,7 +1792,7 @@ public override BigInteger seek(CodeContext/*!*/ context, BigInteger pos, [Optio
17921792 pos = _inner . seek ( context , pos , whence ) ;
17931793 ResetReadBuf ( ) ;
17941794 if ( pos < 0 ) {
1795- throw PythonOps . IOError ( "seek() returned invalid position" ) ;
1795+ throw PythonOps . OSError ( "seek() returned invalid position" ) ;
17961796 }
17971797 GC . KeepAlive ( this ) ;
17981798 return pos ;
@@ -1863,10 +1863,10 @@ public void __init__(
18631863 this . writer = writer ;
18641864
18651865 if ( ! _reader . readable ( context ) ) {
1866- throw PythonOps . IOError ( "\" reader\" object must be readable." ) ;
1866+ throw PythonOps . OSError ( "\" reader\" object must be readable." ) ;
18671867 }
18681868 if ( ! _writer . writable ( context ) ) {
1869- throw PythonOps . IOError ( "\" writer\" object must be writable." ) ;
1869+ throw PythonOps . OSError ( "\" writer\" object must be writable." ) ;
18701870 }
18711871 }
18721872
@@ -2027,7 +2027,7 @@ public void __init__(
20272027 case "\r \n " :
20282028 break ;
20292029 default :
2030- throw PythonOps . ValueError ( string . Format ( "illegal newline value: " + newline ) ) ;
2030+ throw PythonOps . ValueError ( "illegal newline value: {0}" , newline ) ;
20312031 }
20322032
20332033 encoding ??= context . LanguageContext . PythonOptions . Utf8Mode ? "UTF-8" : PythonLocale . PreferredEncoding ;
@@ -2193,10 +2193,10 @@ public override BigInteger write(CodeContext/*!*/ context, object s) {
21932193
21942194 public override BigInteger tell ( CodeContext /*!*/ context ) {
21952195 if ( ! _seekable ) {
2196- throw PythonOps . IOError ( "underlying stream is not seekable" ) ;
2196+ throw PythonOps . OSError ( "underlying stream is not seekable" ) ;
21972197 }
21982198 if ( ! _telling ) {
2199- throw PythonOps . IOError ( "telling position disabled by next() call" ) ;
2199+ throw PythonOps . OSError ( "telling position disabled by next() call" ) ;
22002200 }
22012201
22022202 flush ( context ) ;
@@ -2285,7 +2285,7 @@ public override BigInteger tell(CodeContext/*!*/ context) {
22852285 }
22862286
22872287 if ( charsDecoded < skip ) {
2288- throw PythonOps . IOError ( "can't reconstruct logical file position" ) ;
2288+ throw PythonOps . OSError ( "can't reconstruct logical file position" ) ;
22892289 }
22902290 break ;
22912291 }
@@ -2347,21 +2347,21 @@ public override BigInteger seek(CodeContext/*!*/ context, BigInteger cookie, [Op
23472347 throw PythonOps . ValueError ( "tell on closed file" ) ;
23482348 }
23492349 if ( ! _seekable ) {
2350- throw PythonOps . IOError ( "underlying stream is not seekable" ) ;
2350+ throw PythonOps . OSError ( "underlying stream is not seekable" ) ;
23512351 }
23522352
23532353 IncrementalNewlineDecoder typedDecoder ;
23542354 if ( whenceInt == 1 ) {
23552355 // seek relative to the current position
23562356 if ( cookie != 0 ) {
2357- throw PythonOps . IOError ( "can't do nonzero cur-relative seeks" ) ;
2357+ throw PythonOps . OSError ( "can't do nonzero cur-relative seeks" ) ;
23582358 }
23592359 whenceInt = 0 ;
23602360 cookie = tell ( context ) ;
23612361 } else if ( whenceInt == 2 ) {
23622362 // seek relative to the end of the stream
23632363 if ( cookie != 0 ) {
2364- throw PythonOps . IOError ( "can't do nonzero end-relative seeks" ) ;
2364+ throw PythonOps . OSError ( "can't do nonzero end-relative seeks" ) ;
23652365 }
23662366 flush ( context ) ;
23672367 BigInteger pos = _bufferTyped != null ?
@@ -2452,7 +2452,7 @@ public override BigInteger seek(CodeContext/*!*/ context, BigInteger cookie, [Op
24522452
24532453 // skip appropriate number of decoded chars
24542454 if ( _decodedChars . Length < skip ) {
2455- throw PythonOps . IOError ( "can't restore logical file position" ) ;
2455+ throw PythonOps . OSError ( "can't restore logical file position" ) ;
24562456 }
24572457 _decodedCharsUsed = skip ;
24582458 }
@@ -3218,7 +3218,7 @@ private static bool TryGetInt(object? i, out int value) {
32183218 return Bytes . Make ( s . MakeByteArray ( ) ) ;
32193219 }
32203220
3221- throw PythonOps . TypeError ( "'" + name + " ' should have returned bytes") ;
3221+ throw PythonOps . TypeError ( $ "' { name } ' should have returned bytes") ;
32223222 }
32233223
32243224#nullable restore
0 commit comments