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
On 2/11/21 10:35 PM, Greg Ewing wrote: On 12/02/21 3:39 pm, Andras Tantos wrote: Now, when a Port gets assigned a NetType, it needs to gain all sorts of new features. It for example should have a 'length' attribute that tells how many bits are needed to represent its possible values. The way

Re: super() in injected methods

2021-02-11 Thread Greg Ewing
On 12/02/21 3:39 pm, Andras Tantos wrote: Now, when a Port gets assigned a NetType, it needs to gain all sorts of new features. It for example should have a 'length' attribute that tells how many bits are needed to represent its possible values. The way I would probably approach this is to hav

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
Chris, Thanks for the reply! On 2/11/21 11:08 AM, Chris Angelico wrote: On Fri, Feb 12, 2021 at 5:54 AM Andras Tantos wrote: Esteemed Python Gurus, I think, I actually know the answer to this question, but - maybe beyond reason - I'm hoping there to be some magic. Consider the following co

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
On Fri, Feb 12, 2021 at 5:54 AM Andras Tantos wrote: > > Esteemed Python Gurus, > > I think, I actually know the answer to this question, but - maybe beyond > reason - I'm hoping there to be some magic. Consider the following code: > > from types import MethodType > > class A(object): >

super() in injected methods

2021-02-11 Thread Andras Tantos
Esteemed Python Gurus, I think, I actually know the answer to this question, but - maybe beyond reason - I'm hoping there to be some magic. Consider the following code:     from types import MethodType     class A(object):         pass         def m(self, x):             print(f"A.m({x})")