[issue36827] Overriding __new__ method with itself changes behaviour of the class

2019-06-04 Thread orlnub123
orlnub123 added the comment: The comments in object's source explain the rationale behind this: /* You may wonder why object.__new__() only complains about arguments when object.__init__() is not overridden, and vice versa. Consider the use cases: 1. When neither is overridden, we w

[issue36827] Overriding __new__ method with itself changes behaviour of the class

2019-06-04 Thread Vedran Čačić
Vedran Čačić added the comment: The point is, constructing via __new__ and initializing via __init__ are two mechanisms that aren't really orthogonal, and various heuristics are trying to guess whether the arguments you call your class with are meant for __new__ or for __init__. [Usually, imm

[issue36827] Overriding __new__ method with itself changes behaviour of the class

2019-05-11 Thread Alexey Muranov
Alexey Muranov added the comment: I see that I am not the only one who got bitten by this unexpected behaviour (though the others might have not realised it). There is a question ["Creating a singleton in Python"][1] on StackOverflow which was posted in 2011 and by now has the total of 737

[issue36827] Overriding __new__ method with itself changes behaviour of the class

2019-05-07 Thread Alexey Muranov
Alexey Muranov added the comment: Here is an example of code where i got surprised by the current behaviour and had to apply some (ugly) workaround: https://gist.github.com/alexeymuranov/04e2807eb5679ac7e36da4454a58fa7e -- ___ Python tracker

[issue36827] Overriding __new__ method with itself changes behaviour of the class

2019-05-07 Thread Alexey Muranov
Alexey Muranov added the comment: I've noticed some faults in my code examples: `super(__class__, __class__)` instead of a more appropriate `super(__class__, cls)`, forgotten `return` before `super(__class__, self).foo(*args, **kwarg)`, maybe there are more. I cannot edit previous comments,

[issue36827] Overriding __new__ method with itself changes behaviour of the class

2019-05-07 Thread SilentGhost
Change by SilentGhost : -- nosy: +rhettinger ___ Python tracker ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.pyt

[issue36827] Overriding __new__ method with itself changes behaviour of the class

2019-05-07 Thread Alexey Muranov
Alexey Muranov added the comment: Incidentally, the documentation gives the following signature of __new__: object.__new__(cls[, ...]) which suggests a variable number of arguments. -- ___ Python tracker _

[issue36827] Overriding __new__ method with itself changes behaviour of the class

2019-05-07 Thread Alexey Muranov
Alexey Muranov added the comment: The issue is the following: i expect overriding a method with itself to not change behaviour of the class. I do not see how my understanding of `__new__` or its point could be relevant. Do we agree that overriding a method with itself should not change beha

[issue36827] Overriding __new__ method with itself changes behaviour of the class

2019-05-07 Thread SilentGhost
SilentGhost added the comment: It seems you're misunderstanding the point of __new__ and your usage of it is a bit strange. You're getting an error because you're ultimately calling object.__new__ which doesn't accept any other arguments but the class for instantiation. I'd suggest the docum

[issue36827] Overriding __new__ method with itself changes behaviour of the class

2019-05-07 Thread Alexey Muranov
New submission from Alexey Muranov : I expect that overriding methods with themselves like in the following example should not change the behaviour of the class: class C: a = 1 def __init__(self, b): self.b = b def f(self, x): return x*self