This commit is contained in:
blueloveTH 2025-03-12 14:29:20 +08:00
parent 9ff3417621
commit e51e152b8c
3 changed files with 3 additions and 15 deletions

View File

@ -8,7 +8,6 @@ MAGIC_METHOD(__ge__)
/////////////////////////////
MAGIC_METHOD(__neg__)
MAGIC_METHOD(__abs__)
MAGIC_METHOD(__int__)
MAGIC_METHOD(__round__)
MAGIC_METHOD(__divmod__)
/////////////////////////////

View File

@ -123,9 +123,7 @@ static bool number__pow__(int argc, py_Ref argv) {
return true;
}
static py_i64 i64_abs(py_i64 x) {
return x < 0 ? -x : x;
}
static py_i64 i64_abs(py_i64 x) { return x < 0 ? -x : x; }
static py_i64 cpy11__fast_floor_div(py_i64 a, py_i64 b) {
assert(b != 0);
@ -316,7 +314,7 @@ static bool int__new__(int argc, py_Ref argv) {
return true;
}
case tp_str: break; // leave to the next block
default: return pk_callmagic(__int__, 1, argv + 1);
default: return TypeError("int() argument must be a string, number or boolean");
}
}
// 2+ args -> error

View File

@ -52,13 +52,7 @@ assert A()[1:2, :A()[3:4, ::-1]] == (slice(1, 2, None), slice(None, (slice(3, 4,
assert 2**2**3 == 256
assert (2**2**3)**2 == 65536
class Number:
def __float__(self):
return 1.0
def __int__(self):
return 2
class Number:
def __divmod__(self, other):
return 3, 4
@ -66,9 +60,6 @@ class Number:
return args
assert divmod(Number(), 0) == (3, 4)
assert float(Number()) == 1.0
assert int(Number()) == 2
assert round(Number()) == tuple()
assert round(Number(), 1) == (1,)