Skip to content

Commit 4c8b334

Browse files
committed
Support __index__ in conversion to Int64
1 parent 00c9eb2 commit 4c8b334

File tree

1 file changed

+9
-16
lines changed

1 file changed

+9
-16
lines changed

src/core/IronPython.Modules/fcntl.cs

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -362,22 +362,15 @@ private static bool IsArchitecutreArm64() {
362362
}
363363

364364
private static bool TryGetInt64(object? obj, out long value) {
365-
int success = 1;
366-
value = obj switch {
367-
Missing => default,
368-
int i => i,
369-
uint ui => ui,
370-
long l => l,
371-
ulong ul => (long)ul,
372-
BigInteger bi => (long)bi,
373-
Extensible<BigInteger> ebi => (long)ebi.Value,
374-
byte b => b,
375-
sbyte sb => sb,
376-
short s => s,
377-
ushort us => us,
378-
_ => success = 0
379-
};
380-
return success != 0;
365+
value = default;
366+
if (obj is Missing) {
367+
return true;
368+
}
369+
if (PythonOps.TryToIndex(obj, out BigInteger bi)) {
370+
value = (long)bi;
371+
return true;
372+
}
373+
return false;
381374
}
382375

383376
#endregion

0 commit comments

Comments
 (0)