@@ -61,7 +61,7 @@ public static object __new__(CodeContext context, [NotNone] PythonType cls, [Not
6161 return source ;
6262 } else if ( TryInvokeBytesOperator ( context , source , out Bytes ? res ) ) {
6363 return res ;
64- } else if ( Converter . TryConvertToIndex ( source , out int size , throwNonInt : false ) ) {
64+ } else if ( Converter . TryConvertToIndex ( source , out int size , throwTypeError : false ) ) {
6565 if ( size < 0 ) throw PythonOps . ValueError ( "negative count" ) ;
6666 return new Bytes ( new byte [ size ] ) ;
6767 } else {
@@ -79,7 +79,7 @@ public static object __new__(CodeContext context, [NotNone] PythonType cls, obje
7979 return @object ;
8080 } else if ( TryInvokeBytesOperator ( context , @object , out Bytes ? res ) ) {
8181 return res ;
82- } else if ( Converter . TryConvertToIndex ( @object , out int size , throwNonInt : false ) ) {
82+ } else if ( Converter . TryConvertToIndex ( @object , out int size , throwTypeError : false ) ) {
8383 if ( size < 0 ) throw PythonOps . ValueError ( "negative count" ) ;
8484 return new Bytes ( new byte [ size ] ) ;
8585 } else {
@@ -367,8 +367,13 @@ public int find(BigInteger @byte, object? start, object? end) {
367367 }
368368
369369 [ ClassMethod ]
370- public static object fromhex ( CodeContext context , [ NotNone ] PythonType cls , [ NotNone ] string @string )
371- => __new__ ( context , cls , IListOfByteOps . FromHex ( @string ) ) ;
370+ public static object fromhex ( CodeContext context , [ NotNone ] PythonType cls , [ NotNone ] string @string ) {
371+ var hex = IListOfByteOps . FromHex ( @string ) ;
372+ if ( cls == TypeCache . Bytes ) {
373+ return new Bytes ( hex ) ;
374+ }
375+ return PythonTypeOps . CallParams ( context , cls , new Bytes ( hex ) ) ;
376+ }
372377
373378 public string hex ( ) => ToHex ( _bytes . AsSpan ( ) ) ; // new in CPython 3.5
374379
@@ -1181,6 +1186,13 @@ public bool __eq__(CodeContext context, [NotNone] string value) {
11811186
11821187 public bool __eq__ ( CodeContext context , [ NotNone ] Extensible < string > value ) => __eq__ ( context , value . Value ) ;
11831188
1189+ public bool __eq__ ( CodeContext context , [ NotNone ] int value ) {
1190+ if ( context . LanguageContext . PythonOptions . BytesWarning != Microsoft . Scripting . Severity . Ignore ) {
1191+ PythonOps . Warn ( context , PythonExceptions . BytesWarning , "Comparison between bytes and int" ) ;
1192+ }
1193+ return false ;
1194+ }
1195+
11841196 [ return : MaybeNotImplemented ]
11851197 public NotImplementedType __eq__ ( CodeContext context , object ? value ) => NotImplementedType . Value ;
11861198
@@ -1190,6 +1202,8 @@ public bool __eq__(CodeContext context, [NotNone] string value) {
11901202
11911203 public bool __ne__ ( CodeContext context , [ NotNone ] Extensible < string > value ) => ! __eq__ ( context , value ) ;
11921204
1205+ public bool __ne__ ( CodeContext context , [ NotNone ] int value ) => ! __eq__ ( context , value ) ;
1206+
11931207 [ return : MaybeNotImplemented ]
11941208 public NotImplementedType __ne__ ( CodeContext context , object ? value ) => NotImplementedType . Value ;
11951209
0 commit comments