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‎

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1515,9 +1515,16 @@ func excess_args(args Tuple, kwargs StringDict) bool{
15151515
funcObjectInit(selfObject, argsTuple, kwargsStringDict){
15161516
t:=self.Type()
15171517
// FIXME bodge to compare function pointers
1518-
ifexcess_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+
ift==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
funcObjectNew(t*Type, argsTuple, kwargsStringDict) Object{
15371544
// FIXME bodge to compare function pointers
1538-
ifexcess_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+
ift==ObjectType&&excess_args(args, kwargs){
15391552
panic(ExceptionNewf(TypeError, "object() takes no parameters"))
15401553
}
15411554

0 commit comments

Comments
(0)