Skip to content

Commit 3d702be

Browse files
committed
Fix checking of object.__new__ and __init__ arguments
1 parent 13dc258 commit 3d702be

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

py/type.go

+15-2
Original file line numberDiff line numberDiff line change
@@ -1515,9 +1515,16 @@ func excess_args(args Tuple, kwargs StringDict) bool {
15151515
func ObjectInit(self Object, args Tuple, kwargs StringDict) {
15161516
t := self.Type()
15171517
// FIXME bodge to compare function pointers
1518-
if excess_args(args, kwargs) && (fmt.Sprintf("%p", t.New) == fmt.Sprintf("%p", ObjectNew) || fmt.Sprintf("%p", t.Init) != fmt.Sprintf("%p", ObjectInit)) {
1518+
// if excess_args(args, kwargs) && (fmt.Sprintf("%p", t.New) == fmt.Sprintf("%p", ObjectNew) || fmt.Sprintf("%p", t.Init) != fmt.Sprintf("%p", ObjectInit)) {
1519+
// panic(ExceptionNewf(TypeError, "object.__init__() takes no parameters"))
1520+
// }
1521+
1522+
// FIXME this isn't correct probably
1523+
// Check args for object()
1524+
if t == ObjectType && excess_args(args, kwargs) {
15191525
panic(ExceptionNewf(TypeError, "object.__init__() takes no parameters"))
15201526
}
1527+
15211528
// Call the __init__ method if it exists
15221529
// FIXME this isn't the way cpython does it - it adjusts the function pointers
15231530
// Only do this for non built in types
@@ -1535,7 +1542,13 @@ func ObjectInit(self Object, args Tuple, kwargs StringDict) {
15351542

15361543
func ObjectNew(t *Type, args Tuple, kwargs StringDict) Object {
15371544
// FIXME bodge to compare function pointers
1538-
if excess_args(args, kwargs) && (fmt.Sprintf("%p", t.Init) == fmt.Sprintf("%p", ObjectInit) || fmt.Sprintf("%p", t.New) != fmt.Sprintf("%p", ObjectNew)) {
1545+
// if excess_args(args, kwargs) && (fmt.Sprintf("%p", t.Init) == fmt.Sprintf("%p", ObjectInit) || fmt.Sprintf("%p", t.New) != fmt.Sprintf("%p", ObjectNew)) {
1546+
// panic(ExceptionNewf(TypeError, "object() takes no parameters"))
1547+
// }
1548+
1549+
// FIXME this isn't correct probably
1550+
// Check arguments to new only for object
1551+
if t == ObjectType && excess_args(args, kwargs) {
15391552
panic(ExceptionNewf(TypeError, "object() takes no parameters"))
15401553
}
15411554

0 commit comments

Comments
 (0)