Re: super().__init__() and bytes

2024-12-04 Thread Roel Schroeven via Python-list
Op 4/12/2024 om 0:14 schreef Greg Ewing via Python-list: On 4/12/24 3:24 am, Roel Schroeven wrote: It's not entirely clear to me though how bytes.__new__ *can* set an object's value. Isn't __new__ also a regular function? Yes, but the __new__ methods of the builtin immutable objects (int, str,

Re: super().__init__() and bytes

2024-12-03 Thread Greg Ewing via Python-list
On 4/12/24 3:24 am, Roel Schroeven wrote: It's not entirely clear to me though how bytes.__new__ *can* set an object's value. Isn't __new__ also a regular function? Yes, but the __new__ methods of the builtin immutable objects (int, str, bytes, etc.) are implemented in C, and so are able to do

Re: super().__init__() and bytes

2024-12-03 Thread Roel Schroeven via Python-list
Op 3/12/2024 om 13:55 schreef Anders Munch via Python-list: Roel Schroeven wrote: > As a follow-up, it looks like this behavior is because bytes and int are immutable. Yes. OK. > But that doesn't tell me why using super().__init__() doesn't work for immutable classes. byt

RE: super().__init__() and bytes

2024-12-03 Thread Anders Munch via Python-list
Roel Schroeven wrote: > As a follow-up, it looks like this behavior is because bytes and int are > immutable. Yes. > But that doesn't tell me why using super().__init__() > doesn't work for immutable classes. bytes.__init__ does work, but it's just an inherited o

Re: super().__init__() and bytes

2024-12-03 Thread Roel Schroeven via Python-list
self, data):     super().__init__(data) print(MyBytes(b'abcdefghijlkmn')) This results in an exception: Traceback (most recent call last):   File "test_mybytes.py", line 4, in     print(MyBytes(b'abcdefghijlkmn'))   ^^   File "test_mybytes.

super().__init__() and bytes

2024-12-03 Thread Roel Schroeven via Python-list
We can use super().__init__() in the __init__() method of a derived class to initialize its base class. For example: import string class MyTemplate(string.Template):     def __init__(self, template_string):     super().__init__(template_string) print(MyTemplate('Hello ${name}').

Re: Multiple inheritance and a broken super() chain

2023-07-05 Thread Alan Gauld via Python-list
On 05/07/2023 01:27, Chris Angelico via Python-list wrote: >> So I'm curious about how big this "big problem with MI" is in > > Who said it's a big problem with MI? I think it's a very common perception, particularly with newer programmers who have never used it in anger. Any time anyone discus

Re: Best practices for using super()

2023-07-05 Thread Lars Liedtke via Python-list
/grundsaetze-der-datenverarbeitung.php Am 04.07.23 um 14:20 schrieb Peter Slížik via Python-list: As a follow-up to my yesterday's question - are there any recommendations on the usage of super()? It's clear that super() can be used to invoke parent's: - instance methods -

Re: Multiple inheritance and a broken super() chain

2023-07-04 Thread Chris Angelico via Python-list
On Wed, 5 Jul 2023 at 10:31, Greg Ewing via Python-list wrote: > > On 5/07/23 10:33 am, Alan Gauld wrote: > > (*) C++ is the odd one out because it doesn't have GC, but then > > neither does it have an Object superclass so very often MI in C++ > > does not involve creating diamonds! And especially

Re: Multiple inheritance and a broken super() chain

2023-07-04 Thread Greg Ewing via Python-list
On 5/07/23 10:33 am, Alan Gauld wrote: (*) C++ is the odd one out because it doesn't have GC, but then neither does it have an Object superclass so very often MI in C++ does not involve creating diamonds! And especially if the MI style is mixin based. Even if all your mixins have empty construc

Re: Multiple inheritance and a broken super() chain

2023-07-04 Thread Chris Angelico via Python-list
> > What happens when Top is initialized twice? This seems like a problem > > waiting to happen, and when you moved to using super(), you more than > > likely simplified things and fixed things. > > Slightly off topic but I wonder how many real world problems > people have exp

Re: Multiple inheritance and a broken super() chain

2023-07-04 Thread Alan Gauld via Python-list
happen, and when you moved to using super(), you more than > likely simplified things and fixed things. Slightly off topic but I wonder how many real world problems people have experienced having the top of a diamond initialized twice? The reason I ask is that I ran a maintenance team for abo

Best practices for using super()

2023-07-04 Thread Peter Slížik via Python-list
As a follow-up to my yesterday's question - are there any recommendations on the usage of super()? It's clear that super() can be used to invoke parent's: - instance methods - static methods - constants ("static" attributes in the parent class, e.g. super().NUMBER).

Re: Multiple inheritance and a broken super() chain

2023-07-04 Thread Chris Angelico via Python-list
On Tue, 4 Jul 2023 at 22:06, Peter Slížik via Python-list wrote: > > > > > Also, you might find that because of the MRO, super() in your Bottom > > class would actually give you what you want. > > > > I knew this, but I wanted to save myself some refactoring, as

Re: Multiple inheritance and a broken super() chain

2023-07-04 Thread Peter Slížik via Python-list
> > Also, you might find that because of the MRO, super() in your Bottom > class would actually give you what you want. > I knew this, but I wanted to save myself some refactoring, as the legacy code used different signatures for Left.__init__() and Right.__init__(). I realized the f

Re: Multiple inheritance and a broken super() chain

2023-07-03 Thread Mats Wichmann via Python-list
On 7/3/23 12:13, Mats Wichmann via Python-list wrote: To natter on a bit, and possibly muddy the waters even further... Now, as I see it, from the super()'s point of view, there are two inheritance chains, one starting at Left and the other at Right. But *Right.__init__()* is called twic

Re: Multiple inheritance and a broken super() chain

2023-07-03 Thread Chris Angelico via Python-list
On Tue, 4 Jul 2023 at 03:39, Peter Slížik via Python-list wrote: > > Hello. > > The legacy code I'm working with uses a classic diamond inheritance. Let me > call the classes *Top*, *Left*, *Right*, and *Bottom*. > This is a trivial textbook example. The classes were wri

Re: Multiple inheritance and a broken super() chain

2023-07-03 Thread Mats Wichmann via Python-list
. The classes were written in the pre-super() era, so all of them initialized their parents and Bottom initialized both Left and Right in this order. The result was expected: *Top* was initialized twice: Top.__init__() Left.__init__() Top.__init__() Right.__init__() Bottom.__init__() Now I replace

Re: Multiple inheritance and a broken super() chain

2023-07-03 Thread Richard Damon via Python-list
On 7/3/23 1:38 PM, Peter Slížik via Python-list wrote: Hello. The legacy code I'm working with uses a classic diamond inheritance. Let me call the classes *Top*, *Left*, *Right*, and *Bottom*. This is a trivial textbook example. The classes were written in the pre-super() era, so all of

Multiple inheritance and a broken super() chain

2023-07-03 Thread Peter Slížik via Python-list
Hello. The legacy code I'm working with uses a classic diamond inheritance. Let me call the classes *Top*, *Left*, *Right*, and *Bottom*. This is a trivial textbook example. The classes were written in the pre-super() era, so all of them initialized their parents and Bottom initialized both

Re: When should I use "parent=None" in __ini__ and "parent" in super()

2022-09-02 Thread Cameron Simpson
On 23Sep2021 20:38, Mohsen Owzar wrote: I'm writing since almost one-year codes in Python, using TKinter and PyQt5. I'm somehow able to writes GUIs in both of them. But since I'm using more Pyqt5 and using classes with initialization and super() constructs, and also I saw lot

Re: When should I use "parent=None" in __ini__ and "parent" in super()

2022-09-01 Thread Randy Johnson
Those are contradictory for what you are trying to accomplish unless it is a Parent - Child relationship (MainWindow - Window): When you super() an object, it enherits all the properties from its parent object. Source: https://www.w3schools.com/python/python_inheritance.asp If what you want

Re: Multiple inheritance using super() in parent classes

2022-02-10 Thread Peter Otten
On 10/02/2022 09:20, Igor Basko wrote: Hi everyone, This is my first question here. Hope to get some clarification. Basically this question is about multiple inheritance and the usage of super().__init__ in parent classes. So I have two classes that inherit from the same base class. For example

Multiple inheritance using super() in parent classes

2022-02-10 Thread Igor Basko
Hi everyone, This is my first question here. Hope to get some clarification. Basically this question is about multiple inheritance and the usage of super().__init__ in parent classes. So I have two classes that inherit from the same base class. For example class B and class C inherit from A

When should I use "parent=None" in __ini__ and "parent" in super()

2021-09-23 Thread Mohsen Owzar
Hi Guys I'm writing since almost one-year codes in Python, using TKinter and PyQt5. I'm somehow able to writes GUIs in both of them. But since I'm using more Pyqt5 and using classes with initialization and super() constructs, and also I saw lots of videos and examples of coding

Re: super() in injected methods

2021-02-12 Thread Alan Gauld via Python-list
On 12/02/2021 02:39, Andras Tantos wrote: > 1. Ports, which are the connection points on the various netlist > entities. These would be the inputs and outputs of an AND gate for example > > 2. NetTypes, which describe the type of data that can travel through a > net (and thus through a Port). O

Re: super() in injected methods

2021-02-12 Thread Andras Tantos
change the __class__ of the port object at run time to a subclass of Port having the required features. That would be a lot easier and more efficient than adding individual methods to every Port instance, and super() should work normally. That's actually a pretty good idea, thanks! Let me turn it aro

Re: super() in injected methods

2021-02-11 Thread Greg Ewing
time to a subclass of Port having the required features. That would be a lot easier and more efficient than adding individual methods to every Port instance, and super() should work normally. -- Greg -- https://mail.python.org/mailman/listinfo/python-list

Re: super() in injected methods

2021-02-11 Thread Andras Tantos
On 2/11/21 1:43 PM, Greg Ewing wrote: On 12/02/21 7:05 am, Andras Tantos wrote:      a = B()      a.m(41)      a.m = MethodType(method, a)      a.m(42) Are you sure you really need to inject methods into instances like this? What problem are you trying to solve by doing so? There's almost ce

Re: super() in injected methods

2021-02-11 Thread Andras Tantos
owing code: from types import MethodType class A(object): pass def m(self, x): print(f"A.m({x})") class B(A): def m(self, x): print(f"B.m({x})") ss = super() ss.m(x) def method(self, s): print(f"method({s})") try: ss = super() # <-- Complains about __class__

Re: super() in injected methods

2021-02-11 Thread Greg Ewing
On 12/02/21 7:05 am, Andras Tantos wrote:     a = B()     a.m(41)     a.m = MethodType(method, a)     a.m(42) Are you sure you really need to inject methods into instances like this? What problem are you trying to solve by doing so? There's almost certainly a better way to approach it. --

Re: super() in injected methods

2021-02-11 Thread Chris Angelico
pe > > class A(object): > pass > def m(self, x): > print(f"A.m({x})") > class B(A): > def m(self, x): > print(f"B.m({x})") > ss = super() > ss.m(x) &

super() in injected methods

2021-02-11 Thread Andras Tantos
uot;A.m({x})")     class B(A):         def m(self, x):             print(f"B.m({x})")             ss = super()             ss.m(x)     def method(self, s):         print(f"method({s})")         try:             ss = super() # <-- Complains about __class__ cell not being found

Re: Why does super(bool) give None

2020-04-24 Thread Chris Angelico
On Sat, Apr 25, 2020 at 4:20 AM Random832 wrote: > > On Fri, Apr 24, 2020, at 02:10, Cecil Westerhof wrote: > > issubclass(bool, int) gives True > > but > > super(bool) gives > > > > Do I not understand the meaning of super, or is this inconsistent? > &g

Re: Why does super(bool) give None

2020-04-24 Thread Random832
On Fri, Apr 24, 2020, at 02:10, Cecil Westerhof wrote: > issubclass(bool, int) gives True > but > super(bool) gives > > Do I not understand the meaning of super, or is this inconsistent? I've never heard of a one-argument form for super, but I just tried something and no

Re: Why does super(bool) give None

2020-04-24 Thread Cecil Westerhof
Cecil Westerhof writes: >> I've never actually looked at the repr of a super object - I've always >> just called a method on it immediately after constructing it. Never >> seen a need to hang onto one :) > > Well, maybe I will never need it, but I am just cu

Re: Why does super(bool) give None

2020-04-24 Thread Cecil Westerhof
Chris Angelico writes: > On Fri, Apr 24, 2020 at 4:16 PM Cecil Westerhof wrote: >> >> issubclass(bool, int) gives True >> but >> super(bool) gives >> >> Do I not understand the meaning of super, or is this inconsistent? >> >> (Until n

Re: Why does super(bool) give None

2020-04-23 Thread Chris Angelico
On Fri, Apr 24, 2020 at 4:16 PM Cecil Westerhof wrote: > > issubclass(bool, int) gives True > but > super(bool) gives > > Do I not understand the meaning of super, or is this inconsistent? > > (Until now I have not down much work with classes in Python.) > One-arg

Why does super(bool) give None

2020-04-23 Thread Cecil Westerhof
issubclass(bool, int) gives True but super(bool) gives Do I not understand the meaning of super, or is this inconsistent? (Until now I have not down much work with classes in Python.) -- Cecil Westerhof Senior Software Engineer LinkedIn: http://www.linkedin.com/in/cecilwesterhof -- https

Re: Better use a class decorator or a metaclass?(was: super not behaving as I expected)

2020-04-04 Thread Souvik Dutta
I think this should help https://stackoverflow.com/questions/1779372/python-metaclasses-vs-class-decorators On Sat, 4 Apr, 2020, 6:12 pm Antoon Pardon, wrote: > Op 29/03/20 om 16:49 schreef Peter Otten: > > Antoon Pardon wrote: > > > >> > >> I have the following program > >> > >> class slt: > >>

Better use a class decorator or a metaclass?(was: super not behaving as I expected)

2020-04-04 Thread Antoon Pardon
Op 29/03/20 om 16:49 schreef Peter Otten: > Antoon Pardon wrote: > >> >> I have the following program >> >> class slt: >> __slots__ = () >> ... >> >> class slt1 (slt): >> __slots__ = 'fld1', 'fld2' >> ... >> >> class slt2(slt1): >> __slots__ = 'fld3', >> > Anyway, here's my attempt to

Re: super not behaving as I expected

2020-03-29 Thread Peter Otten
Antoon Pardon wrote: > > I have the following program > > class slt: > __slots__ = () > > def getslots(self): > print("### slots =", self.__slots__) > if self.__slots__ == (): > return [] > else: > ls = super().getslots() > ls.extend(self.__

super not behaving as I expected

2020-03-29 Thread Antoon Pardon
I have the following program class slt: __slots__ = () def getslots(self): print("### slots =", self.__slots__) if self.__slots__ == (): return [] else: ls = super(

Re: How does the super type present itself and do lookups?

2020-03-24 Thread Greg Ewing
it took me a while to figure out what was happening here myself! I think the problem is that the act of looking up __getattribute__ on the super object invokes the super object's magic lookup machinery, and ends up giving a misleading result. It's clearer if you look for __getattribu

Re: How does the super type present itself and do lookups?

2020-03-22 Thread Adam Preble
int out with the same address and pass an equality comparison. That implies that they are the same, and that the super type is NOT doing something special with that slot. Given that super().__getattribute__ internally ultimately should be something else, I am guessing there is something else at p

Re: How does the super type present itself and do lookups?

2020-03-19 Thread Greg Ewing
On 11/03/20 7:02 am, Adam Preble wrote: Is this foo attribute being looked up in an override of __getattr__, __getattribute__, or is it a reserved slot that's internally doing this? That's what I'm trying to figure out. Looking at the source in Objects/typeobject.c, it uses the tp_getattro ty

Re: How does the super type present itself and do lookups?

2020-03-10 Thread Adam Preble
On Tuesday, March 10, 2020 at 9:28:11 AM UTC-5, Peter Otten wrote: > self.foo looks up the attribute in the instance, falls back to the class and > then works its way up to the parent class, whereas > > super().foo bypasses both instance and class, and starts its lookup in the &g

Re: How does the super type present itself and do lookups?

2020-03-10 Thread Barry Scott
> On 4 Mar 2020, at 17:12, Adam Preble wrote: > > Months ago, I asked a bunch of stuff about super() and managed to fake it > well enough to move on to other things for awhile. The day of reckoning came > this week and I was forced to implement it better for my personal Pytho

Re: How does the super type present itself and do lookups?

2020-03-10 Thread Peter Otten
Adam Preble wrote: > If you don't know, you can trap what super() returns some time and poke it > with a stick. If you print it you'll be able to tell it's definitely > unique: , > > > If you try to invoke methods on it, it'll invoke the superclass' m

Re: How does the super type present itself and do lookups?

2020-03-09 Thread Adam Preble
On Monday, March 9, 2020 at 9:31:45 PM UTC-5, Souvik Dutta wrote: > This should be what you are looking for. > https://python-reference.readthedocs.io/en/latest/docs/functions/super.html I'm not trying to figure out how the super() function works, but rather the anatomy of the object

Re: How does the super type present itself and do lookups?

2020-03-09 Thread Souvik Dutta
This should be what you are looking for. https://python-reference.readthedocs.io/en/latest/docs/functions/super.html On Tue, 10 Mar, 2020, 5:50 am Adam Preble, wrote: > On Wednesday, March 4, 2020 at 11:13:20 AM UTC-6, Adam Preble wrote: > > Stuff > > I'm speculating that the stuff I don't see w

Re: How does the super type present itself and do lookups?

2020-03-09 Thread Adam Preble
On Wednesday, March 4, 2020 at 11:13:20 AM UTC-6, Adam Preble wrote: > Stuff I'm speculating that the stuff I don't see when poking are reserved slots. I figured out how much of a thing that is when I was digging around for how classes know how to construct themselves. I managed to figure out __

How does the super type present itself and do lookups?

2020-03-04 Thread Adam Preble
Months ago, I asked a bunch of stuff about super() and managed to fake it well enough to move on to other things for awhile. The day of reckoning came this week and I was forced to implement it better for my personal Python project. I have a hack in place that makes it work well-enough but I

Re: Extending property using a Subclass - single method - why Super(Baz, Baz).name.__set__ ?

2019-12-03 Thread Peter Otten
lass/instance-name-ref > > Note that he's receiving instance-references > > therefore when I start sub-classing a property why does he then switch to > class-references/class-variables If you were subclassing a property you'd do class my_property(property): # tinker

Re: Extending property using a Subclass - single method - why Super(Baz, Baz).name.__set__ ?

2019-12-03 Thread Veek M
you've misunderstood my question, let me try again: So this is a simple descriptor class and as you can see, dunder-set needs 3 args: the descriptor CONTAINER/Bar-instance is the first arg, then a reference to the using instance/Foo-instance class Bar(object): def __set__(self, instanc

Re: Extending property using a Subclass - single method - why Super(Baz, Baz).name.__set__ ?

2019-12-03 Thread Peter Otten
t; print('Foo', name) > > class Baz(Foo): > @property > def name(self): > print('Baz wrapper around getter') > return super().name > > @Foo.name.setter This looks like a bug as the read-only property defined abov

Extending property using a Subclass - single method - why Super(Baz, Baz).name.__set__ ?

2019-12-03 Thread Veek M
#x27;Foo', self) self._name = value print(self._name) @name.deleter def name(self): print('del') self._name = None print('Foo', name) class Baz(Foo): @property def name(self): pr

Re: Instantiating sub-class from super

2019-10-24 Thread DL Neil via Python-list
On 25/10/19 4:29 AM, Frank Millman wrote: On 2019-10-19 12:37 AM, DL Neil via Python-list wrote: On 16/10/19 6:33 PM, Frank Millman wrote: On 2019-10-14 10:55 PM, DL Neil via Python-list wrote: Is there a technique or pattern for taking a (partially-) populated instance of a class, and re-crea

Re: Instantiating sub-class from super

2019-10-24 Thread Frank Millman
On 2019-10-19 12:37 AM, DL Neil via Python-list wrote: On 16/10/19 6:33 PM, Frank Millman wrote: On 2019-10-14 10:55 PM, DL Neil via Python-list wrote: Is there a technique or pattern for taking a (partially-) populated instance of a class, and re-creating it as an instance of one of its sub-c

Re: Instantiating sub-class from super

2019-10-19 Thread duncan smith
On 18/10/2019 23:57, DL Neil wrote: > On 17/10/19 7:52 AM, MRAB wrote: >> On 2019-10-16 19:43, duncan smith wrote: >>> On 16/10/2019 04:41, DL Neil wrote: On 16/10/19 1:55 PM, duncan smith wrote: > On 15/10/2019 21:36, DL Neil wrote: >> On 16/10/19 12:38 AM, Rhodri James wrote: >>>

Re: Instantiating sub-class from super

2019-10-18 Thread DL Neil via Python-list
On 18/10/19 9:27 AM, Eryk Sun wrote: On 10/17/19, MRAB wrote: On 2019-10-17 20:06, Eryk Sun wrote: I'm bugged by how the article mis-characterizes the fundamental problem. The operating system has nothing to do with the order of a directory listing, which varies even with an OS, depending on

Re: Instantiating sub-class from super

2019-10-18 Thread DL Neil via Python-list
On 17/10/19 7:52 AM, MRAB wrote: On 2019-10-16 19:43, duncan smith wrote: On 16/10/2019 04:41, DL Neil wrote: On 16/10/19 1:55 PM, duncan smith wrote: On 15/10/2019 21:36, DL Neil wrote: On 16/10/19 12:38 AM, Rhodri James wrote: On 14/10/2019 21:55, DL Neil via Python-list wrote: ... So, ye

Re: Instantiating sub-class from super

2019-10-18 Thread DL Neil via Python-list
On 17/10/19 4:08 AM, Piet van Oostrum wrote: DL Neil writes: That said, if a "trans" person has ovaries or testes (for example) then a non-traditional sexual identification is irrelevant - for medical purposes. Diseases in those areas (and now I'm a long way from a research questionnaire and f

Re: Instantiating sub-class from super

2019-10-18 Thread DL Neil via Python-list
On 16/10/19 6:33 PM, Frank Millman wrote: On 2019-10-14 10:55 PM, DL Neil via Python-list wrote: Is there a technique or pattern for taking a (partially-) populated instance of a class, and re-creating it as an instance of one of its sub-classes? Here is a link to an article entitled 'Underst

Re: Instantiating sub-class from super

2019-10-17 Thread Eryk Sun
On 10/17/19, MRAB wrote: > On 2019-10-17 20:06, Eryk Sun wrote: > >> I'm bugged by how the article mis-characterizes the fundamental >> problem. The operating system has nothing to do with the order of a >> directory listing, which varies even with an OS, depending on the file >> system. The latte

Re: Instantiating sub-class from super

2019-10-17 Thread MRAB
On 2019-10-17 20:06, Eryk Sun wrote: On 10/17/19, Dennis Lee Bieber wrote: On Wed, 16 Oct 2019 19:52:50 +0100, MRAB declaimed the following: Researchers find bug in Python script may have affected hundreds of studies https://arstechnica.com/information-technology/2019/10/chemists-discover-cr

Re: Instantiating sub-class from super

2019-10-17 Thread Eryk Sun
On 10/17/19, Dennis Lee Bieber wrote: > On Wed, 16 Oct 2019 19:52:50 +0100, MRAB > declaimed the following: > >>Researchers find bug in Python script may have affected hundreds of >> studies >>https://arstechnica.com/information-technology/2019/10/chemists-discover-cross-platform-python-scripts-n

Re: Instantiating sub-class from super

2019-10-16 Thread Frank Millman
On 2019-10-16 7:33 AM, Frank Millman wrote: Here is a link to an article entitled 'Understanding Hidden Subtypes'. It dates back to 2004, but I think it is still relevant. It addresses precisely the issues that you raise, but from a data-modelling perspective, not a programming one. http://

Re: Instantiating sub-class from super

2019-10-16 Thread duncan smith
On 16/10/2019 19:52, MRAB wrote: > On 2019-10-16 19:43, duncan smith wrote: >> On 16/10/2019 04:41, DL Neil wrote: >>> On 16/10/19 1:55 PM, duncan smith wrote: On 15/10/2019 21:36, DL Neil wrote: > On 16/10/19 12:38 AM, Rhodri James wrote: >> On 14/10/2019 21:55, DL Neil via Python-lis

Re: Instantiating sub-class from super

2019-10-16 Thread Barry Scott
> On 14 Oct 2019, at 21:55, DL Neil via Python-list > wrote: > > Is there a technique or pattern for taking a (partially-) populated instance > of a class, and re-creating it as an instance of one of its sub-classes? The pattern I know is to use a factory function to choose between a number

Re: Instantiating sub-class from super

2019-10-16 Thread MRAB
On 2019-10-16 19:43, duncan smith wrote: On 16/10/2019 04:41, DL Neil wrote: On 16/10/19 1:55 PM, duncan smith wrote: On 15/10/2019 21:36, DL Neil wrote: On 16/10/19 12:38 AM, Rhodri James wrote: On 14/10/2019 21:55, DL Neil via Python-list wrote: ... So, yes, the "label" is unimportant - ex

Re: Instantiating sub-class from super

2019-10-16 Thread duncan smith
On 16/10/2019 04:41, DL Neil wrote: > On 16/10/19 1:55 PM, duncan smith wrote: >> On 15/10/2019 21:36, DL Neil wrote: >>> On 16/10/19 12:38 AM, Rhodri James wrote: On 14/10/2019 21:55, DL Neil via Python-list wrote: >>> ... >>> So, yes, the "label" is unimportant - except to politicians and >>

Re: Instantiating sub-class from super

2019-10-16 Thread Piet van Oostrum
DL Neil writes: > That said, if a "trans" person has ovaries or testes (for example) then > a non-traditional sexual identification is irrelevant - for medical > purposes. Diseases in those areas (and now I'm a long way from a > research questionnaire and from Python - but this is roughly how it

Re: Instantiating sub-class from super

2019-10-15 Thread Frank Millman
On 2019-10-14 10:55 PM, DL Neil via Python-list wrote: Is there a technique or pattern for taking a (partially-) populated instance of a class, and re-creating it as an instance of one of its sub-classes? In a medically-oriented situation, we have a Person() class, and start collecting infor

Re: Instantiating sub-class from super

2019-10-15 Thread DL Neil via Python-list
On 16/10/19 1:55 PM, duncan smith wrote: On 15/10/2019 21:36, DL Neil wrote: On 16/10/19 12:38 AM, Rhodri James wrote: On 14/10/2019 21:55, DL Neil via Python-list wrote: ... So, yes, the "label" is unimportant - except to politicians and statisticians, who want precise answers from vague coll

Re: Instantiating sub-class from super

2019-10-15 Thread duncan smith
On 15/10/2019 21:36, DL Neil wrote: > On 16/10/19 12:38 AM, Rhodri James wrote: >> On 14/10/2019 21:55, DL Neil via Python-list wrote: > ... > >>> It seemed better (at the design-level) to have Man( Person ) and >>> Woman( Person ) sub-classes to contain the pertinent attributes, >>> source more d

Re: Instantiating sub-class from super

2019-10-15 Thread DL Neil via Python-list
On 16/10/19 12:38 AM, Rhodri James wrote: On 14/10/2019 21:55, DL Neil via Python-list wrote: ... It seemed better (at the design-level) to have Man( Person ) and Woman( Person ) sub-classes to contain the pertinent attributes, source more detailed and specific questions, and collect such dat

Re: Instantiating sub-class from super

2019-10-15 Thread Rhodri James
On 14/10/2019 21:55, DL Neil via Python-list wrote: Is there a technique or pattern for taking a (partially-) populated instance of a class, and re-creating it as an instance of one of its sub-classes? In a medically-oriented situation, we have a Person() class, and start collecting informat

Re: Instantiating sub-class from super

2019-10-14 Thread DL Neil via Python-list
Person-instance is 'converted'* into a Male-instance, then Male.__init__() will not be executed. (haven't bothered to experiment with an explicit call, because...) In this case, that is not an issue, because apart from the value of "sex", the __init__() actions

Re: Instantiating sub-class from super

2019-10-14 Thread Gregory Ewing
DL Neil wrote: Is there a technique or pattern for taking a (partially-) populated instance of a class, and re-creating it as an instance of one of its sub-classes? Often you can assign to the __class__ attribute of an instance to change its class. Python 3.7.3 (default, Apr 8 2019, 22:20:19

Instantiating sub-class from super

2019-10-14 Thread DL Neil via Python-list
Is there a technique or pattern for taking a (partially-) populated instance of a class, and re-creating it as an instance of one of its sub-classes? In a medically-oriented situation, we have a Person() class, and start collecting information within an instance (person = Person(), etc). Du

Re: super() in Python 3

2019-07-17 Thread DL Neil
On 16/07/19 10:08 PM, אורי wrote: Hi, 1. When we use super() in Python 3, we don't pass it the first argument (self). Why? What happens if the first argument is not self? def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) I think it would make more sense t

Re: super or not super?

2019-07-16 Thread Paulo da Silva
Às 02:11 de 15/07/19, Chris Angelico escreveu: > On Mon, Jul 15, 2019 at 10:51 AM Paulo da Silva > wrote: >> ... >> >> Thank you Jollans. I forgot multiple inheritance. I never needed it in >> python, so far. >> > > Something to consider is that sup

Re: super or not super?

2019-07-16 Thread Chris Angelico
On Wed, Jul 17, 2019 at 3:58 AM Ian Kelly wrote: > > On Tue, Jul 16, 2019 at 1:21 AM Chris Angelico wrote: > > > > On Tue, Jul 16, 2019 at 3:32 PM Ian Kelly wrote: > > > > > > Just using super() is not enough. You need to take steps if you want to > >

Re: super or not super?

2019-07-16 Thread Ian Kelly
On Tue, Jul 16, 2019 at 1:21 AM Chris Angelico wrote: > > On Tue, Jul 16, 2019 at 3:32 PM Ian Kelly wrote: > > > > Just using super() is not enough. You need to take steps if you want to > > ensure that you class plays nicely with MI. For example, consider the > &g

Re: super() in Python 3

2019-07-16 Thread Rhodri James
suite(self, test_labels=None, *args, **kwargs): ... return super().build_suite(test_labels=test_labels, *args, **kwargs) > > Thanks for your explanation. But I tried your code and it doesn't work > (with Django==1.11.22): > >File "<...>\site-packages\djan

Re: super() in Python 3

2019-07-16 Thread אורי
ase\test\models.py", line 35, in build_suite return super().build_suite(test_labels=test_labels, *args, **kwargs) TypeError: build_suite() got multiple values for argument 'test_labels' אורי u...@speedy.net On Tue, Jul 16, 2019 at 3:13 PM Rhodri James wrote: > Hi there! A

Re: super() in Python 3

2019-07-16 Thread Rhodri James
Hi there! A lot of the answers to your questions are at least implied in the Fine Manual (https://docs.python.org/3/library/functions.html#super), but it's not very clear and written more for precision than comprehension. Here's my attempt at explaining :-) On 16/07/2019 11:08,

Re: super or not super?

2019-07-16 Thread Antoon Pardon
On 16/07/19 10:18, Chris Angelico wrote: > On Tue, Jul 16, 2019 at 6:05 PM Antoon Pardon wrote: >> On 16/07/19 09:18, Chris Angelico wrote: >>> On Tue, Jul 16, 2019 at 3:32 PM Ian Kelly wrote: >>>> Just using super() is not enough. You need to take steps if you want

super() in Python 3

2019-07-16 Thread אורי
Hi, 1. When we use super() in Python 3, we don't pass it the first argument (self). Why? What happens if the first argument is not self? def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) I think it would make more sense to use something like self.super().__init__(

Re: super or not super?

2019-07-16 Thread Chris Angelico
On Tue, Jul 16, 2019 at 6:05 PM Antoon Pardon wrote: > > On 16/07/19 09:18, Chris Angelico wrote: > > On Tue, Jul 16, 2019 at 3:32 PM Ian Kelly wrote: > >> Just using super() is not enough. You need to take steps if you want to > >> ensure that you class pla

Re: super or not super?

2019-07-16 Thread Antoon Pardon
ans escreveu: >>>>> On 12/07/2019 16.12, Paulo da Silva wrote: >>>>>> Hi all! >>>>>> >>>>>> Is there any difference between using the base class name or super to >>>>>> call __init__ from base class? >>&

Re: super or not super?

2019-07-16 Thread Chris Angelico
On 12/07/2019 16.12, Paulo da Silva wrote: > > > >> Hi all! > > > >> > > > >> Is there any difference between using the base class name or super to > > > >> call __init__ from base class? > > > > > > >

Re: super or not super?

2019-07-15 Thread Ian Kelly
> > >> Is there any difference between using the base class name or super to > > >> call __init__ from base class? > > > > > > There is, when multiple inheritance is involved. super() can call > > > different 'branches' of the inhe

Re: super or not super?

2019-07-15 Thread Barry Scott
> On 12 Jul 2019, at 15:12, Paulo da Silva > wrote: > > Hi all! > > Is there any difference between using the base class name or super to > call __init__ from base class? > > class C1: > def __init__(self): > ... > >

Re: super or not super?

2019-07-14 Thread Chris Angelico
On Mon, Jul 15, 2019 at 10:51 AM Paulo da Silva wrote: > > Às 15:30 de 12/07/19, Thomas Jollans escreveu: > > On 12/07/2019 16.12, Paulo da Silva wrote: > >> Hi all! > >> > >> Is there any difference between using the base class name or super to > >&

Re: super or not super?

2019-07-14 Thread Paulo da Silva
Às 16:20 de 12/07/19, Rhodri James escreveu: > On 12/07/2019 15:12, Paulo da Silva wrote: > ... > super() also has major advantages if you are stuck with multiple > inheritance.  Raymond Hettinger has an excellent article on this here: > https://rhettinger.wordpress.com/2

Re: super or not super?

2019-07-14 Thread Paulo da Silva
Às 15:30 de 12/07/19, Thomas Jollans escreveu: > On 12/07/2019 16.12, Paulo da Silva wrote: >> Hi all! >> >> Is there any difference between using the base class name or super to >> call __init__ from base class? > > There is, when multiple inheritance is invol

Re: super or not super?

2019-07-12 Thread Thomas Jollans
On 12/07/2019 16.12, Paulo da Silva wrote: > Hi all! > > Is there any difference between using the base class name or super to > call __init__ from base class? There is, when multiple inheritance is involved. super() can call different 'branches' of the inheritance tree

Re: super or not super?

2019-07-12 Thread Rhodri James
On 12/07/2019 15:12, Paulo da Silva wrote: Hi all! Is there any difference between using the base class name or super to call __init__ from base class? class C1: def __init__(self): ... class C2(C1): def __init__(self): C1.__init__(self) or

  1   2   3   4   5   6   7   8   9   >