Re: Odd types.get_original_bases() behavior for classes with generic bases but no type arguments

2023-07-24 Thread Chris Bouchard via Python-list
> >>> Example.__bases__ > (First, Second) Sorry, that should have been >>> Example.__bases__ (, ) That's what I get for writing an example from memory rather than copying it from a REPL session. It doesn't change the point I wanted to make, though. Thanks, Chris Bouchard -- https://mail.python

Odd types.get_original_bases() behavior for classes with generic bases but no type arguments

2023-07-24 Thread Chris Bouchard via Python-list
(Apologies if this has already been discussed. I tried to search and didn't find anything relevant.) I was playing around with 3.12.0b4 this evening and noticed an odd (to me, at least) behavior with types.get_original_bases(). I hesitate to call it a bug because I think I understand *why* it's be

Re: Enums and nested classes

2022-04-21 Thread Ethan Furman
On 4/21/22 15:00, Greg Ewing wrote: On 20/04/22 10:57 pm, Sam Ezeh wrote: Has anyone here used or attempted to use a nested class inside an enum? If so, how did you find it? (what did you expect to happen and did your expectations align with resulting behaviour etc.) That's a pretty open-ende

Re: Enums and nested classes

2022-04-21 Thread Greg Ewing
On 20/04/22 10:57 pm, Sam Ezeh wrote: Has anyone here used or attempted to use a nested class inside an enum? If so, how did you find it? (what did you expect to happen and did your expectations align with resulting behaviour etc.) That's a pretty open-ended question. Is there something about

Enums and nested classes

2022-04-20 Thread Sam Ezeh
Hello everyone, Has anyone here used or attempted to use a nested class inside an enum? If so, how did you find it? (what did you expect to happen and did your expectations align with resulting behaviour etc.) Here are two examples describing the situation I'm talking about ``` class Outer(Enum

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

RE: builtins.TypeError: catching classes that do not inherit from BaseException is not allowed

2021-12-31 Thread Avi Gross via Python-list
half Of Karsten Hilbert Sent: Friday, December 31, 2021 7:09 AM To: python-list@python.org Subject: Re: builtins.TypeError: catching classes that do not inherit from BaseException is not allowed Am Thu, Dec 30, 2021 at 03:57:25PM -0800 schrieb hongy...@gmail.com: > > > Then what cases/scena

Re: builtins.TypeError: catching classes that do not inherit from BaseException is not allowed

2021-12-31 Thread hongy...@gmail.com
On Friday, December 31, 2021 at 4:18:28 PM UTC+8, Marco Sulla wrote: > It was already done: https://pypi.org/project/tail-recursive/ A few days ago, I also noticed another similar project: https://github.com/baruchel/tco It seems that they are very similar, even identical. But I'm not sure, so I

Re: builtins.TypeError: catching classes that do not inherit from BaseException is not allowed

2021-12-31 Thread hongy...@gmail.com
On Friday, December 31, 2021 at 7:17:18 PM UTC+8, hongy...@gmail.com wrote: > On Friday, December 31, 2021 at 4:18:28 PM UTC+8, Marco Sulla wrote: > > It was already done: https://pypi.org/project/tail-recursive/ > A few days ago, I also noticed another similar project: > https://github.com/baruc

Re: builtins.TypeError: catching classes that do not inherit from BaseException is not allowed

2021-12-31 Thread Karsten Hilbert
Am Thu, Dec 30, 2021 at 03:57:25PM -0800 schrieb hongy...@gmail.com: > > > Then what cases/scenarios can demonstrate the beauty of recursion? > > > > > Walking a tree. > > There are many type of trees. Do you mean all of them? Palm trees don't lend themselves to recursion all that much. Karsten

Re: builtins.TypeError: catching classes that do not inherit from BaseException is not allowed

2021-12-31 Thread Marco Sulla
ctorial > return factorial(n-1, n*acc) > File "/home/werner/this-script.py", line 28, in func > raise TailRecurseException(args, kwargs) > TypeError: exceptions must derive from BaseException > > During handling of the above exception, another exception occurred: >

RE: builtins.TypeError: catching classes that do not inherit from BaseException is not allowed

2021-12-30 Thread Avi Gross via Python-list
integers though, ... -Original Message- From: Python-list On Behalf Of hongy...@gmail.com Sent: Thursday, December 30, 2021 6:27 PM To: python-list@python.org Subject: Re: builtins.TypeError: catching classes that do not inherit from BaseException is not allowed On Friday, December 31

Re: builtins.TypeError: catching classes that do not inherit from BaseException is not allowed

2021-12-30 Thread hongy...@gmail.com
On Friday, December 31, 2021 at 7:50:48 AM UTC+8, MRAB wrote: > On 2021-12-30 23:27, hongy...@gmail.com wrote: > > On Friday, December 31, 2021 at 7:04:24 AM UTC+8, Chris Angelico wrote: > >> Neither of these wants to be recursive, and writing them recursively > >> pollutes the function signatur

Re: builtins.TypeError: catching classes that do not inherit from BaseException is not allowed

2021-12-30 Thread MRAB
On 2021-12-30 23:27, hongy...@gmail.com wrote: On Friday, December 31, 2021 at 7:04:24 AM UTC+8, Chris Angelico wrote: Neither of these wants to be recursive, and writing them recursively pollutes the function signature with parameters that really exist just to be local variables. Passing an ac

Re: builtins.TypeError: catching classes that do not inherit from BaseException is not allowed

2021-12-30 Thread hongy...@gmail.com
On Friday, December 31, 2021 at 7:04:24 AM UTC+8, Chris Angelico wrote: > Neither of these wants to be recursive, and writing them recursively > pollutes the function signature with parameters that really exist just > to be local variables. Passing an accumulator down is a terrible way > to demo

Re: builtins.TypeError: catching classes that do not inherit from BaseException is not allowed

2021-12-30 Thread Chris Angelico
On Fri, Dec 31, 2021 at 9:42 AM hongy...@gmail.com wrote: > > (Also, is this REALLY an optimization? Exception handling isn't the > > fastest. Yes, it avoids some measure of recursion depth, but it looks > > like a pretty inefficient way to do things. Python is not Lisp, and > > there are very ver

Re: builtins.TypeError: catching classes that do not inherit from BaseException is not allowed

2021-12-30 Thread Chris Angelico
gt; > > > > > [1] > > > https://discuss.python.org/t/typeerror-catching-classes-that-do-not-inherit-from-baseexception-is-not-allowed/12800 > > Why did you post in two places at once? Did you need more people to > > tell you the same thing as the error message? > >

Re: builtins.TypeError: catching classes that do not inherit from BaseException is not allowed

2021-12-30 Thread hongy...@gmail.com
On Thursday, December 30, 2021 at 11:23:35 PM UTC+8, Chris Angelico wrote: > If it's an exception, it needs to subclass Exception or BaseException. I see. That is, the following: class TailRecurseException(Exception): def __init__(self, args, kwargs): self.args = args self.kwargs = kwa

Re: builtins.TypeError: catching classes that do not inherit from BaseException is not allowed

2021-12-30 Thread hongy...@gmail.com
On Thursday, December 30, 2021 at 11:24:20 PM UTC+8, Chris Angelico wrote: > On Fri, Dec 31, 2021 at 2:03 AM hongy...@gmail.com > wrote: > > See here [1] for the related discussion. > > > > [1] > > https://discuss.python.org/t/typeerror-catching-classes-that-do-

Re: builtins.TypeError: catching classes that do not inherit from BaseException is not allowed

2021-12-30 Thread Chris Angelico
On Fri, Dec 31, 2021 at 2:03 AM hongy...@gmail.com wrote: > See here [1] for the related discussion. > > [1] > https://discuss.python.org/t/typeerror-catching-classes-that-do-not-inherit-from-baseexception-is-not-allowed/12800 Why did you post in two places at once? Did you need mo

Re: builtins.TypeError: catching classes that do not inherit from BaseException is not allowed

2021-12-30 Thread Chris Angelico
On Fri, Dec 31, 2021 at 2:00 AM hongy...@gmail.com wrote: > > I try to compute the factorial of a large number with tail-recursion > optimization decorator in Python3. The following code snippet is converted > from the code snippet given here [1] by the following steps: > > $ pyenv shell datasci

Re: builtins.TypeError: catching classes that do not inherit from BaseException is not allowed

2021-12-30 Thread hongy...@gmail.com
aise TailRecurseException(args, kwargs) > TypeError: exceptions must derive from BaseException > > During handling of the above exception, another exception occurred: > > Traceback (most recent call last): > File "/home/werner/this-script.py", line 46, in > p

builtins.TypeError: catching classes that do not inherit from BaseException is not allowed

2021-12-30 Thread hongy...@gmail.com
ng handling of the above exception, another exception occurred: Traceback (most recent call last): File "/home/werner/this-script.py", line 46, in print(factorial(1)) File "/home/werner/this-script.py", line 33, in func except TailRecurseException as e: TypeError: ca

Instantiating abstract classes

2021-05-21 Thread Peter Otten
Usually an abstract class cannot be instantiated: >>> from abc import ABCMeta, abstractmethod >>> from fractions import Fraction >>> class A(Fraction, metaclass=ABCMeta): @abstractmethod def frobnicate(self): pass >>> A() Traceback (most recent call last): File "", lin

Re: Immutable view classes - inherit from dict or from Mapping?

2021-04-13 Thread Serhiy Storchaka
13.04.21 15:47, Peter Otten пише: > As to the | operator, maybe it could be added to Mapping? The | operator returns a new instance, but constructor is not a part of the Mapping interface. You cannot make a general implementation, and making __or__ an abstract method will break all existing Mappin

Re: Immutable view classes - inherit from dict or from Mapping?

2021-04-13 Thread Serhiy Storchaka
12.04.21 19:01, Andreas R Maier пише: > Hi, > I have written some classes that represent immutable views on collections > (see "immutable-views" package on Pypi). > > Currently, these view classes inherit from the abstract collection classes > such as Mapping,

Re: Immutable view classes - inherit from dict or from Mapping?

2021-04-13 Thread Peter Otten
On 12/04/2021 18:01, Andreas R Maier wrote: Hi, I have written some classes that represent immutable views on collections (see "immutable-views" package on Pypi). Currently, these view classes inherit from the abstract collection classes such as Mapping, Sequence, Set. However, they

Immutable view classes - inherit from dict or from Mapping?

2021-04-12 Thread Andreas R Maier
Hi, I have written some classes that represent immutable views on collections (see "immutable-views" package on Pypi). Currently, these view classes inherit from the abstract collection classes such as Mapping, Sequence, Set. However, they implement the read-only methods of dict, li

Friday Finking: Abstract Base Classes - love or hate

2021-01-14 Thread dn via Python-list
Do you make frequent use of Abstract Base Classes (ABCs), prefer to use an ordinary super-class for the same purpose, or steer-clear? Are they more-usually employed when the project includes an extensive design stage, and the meta-class integral to some hierarchy of entities? Previous Friday

Re: Question on ABC classes

2020-10-29 Thread Chris Angelico
On Fri, Oct 30, 2020 at 5:16 PM Julio Di Egidio wrote: > Not to mention, from the point of view of formal verification, > this is the corresponding annotated version, and it is in fact > worse than useless: > > def abs(x: Any) -> Any: > ...some code here... > Useless because, in the absence of

Re: Question on ABC classes

2020-10-29 Thread Julio Di Egidio
On Friday, 30 October 2020 05:09:34 UTC+1, Chris Angelico wrote: > On Fri, Oct 30, 2020 at 1:06 PM Julio Di Egidio wrote: > > On Sunday, 25 October 2020 20:55:26 UTC+1, Peter J. Holzer wrote: > > > I think you are trying to use Python in a way contrary to its nature. > > > Python is a dynamicall

Re: Question on ABC classes

2020-10-29 Thread Chris Angelico
On Fri, Oct 30, 2020 at 1:06 PM Julio Di Egidio wrote: > > On Sunday, 25 October 2020 20:55:26 UTC+1, Peter J. Holzer wrote: > > I think you are trying to use Python in a way contrary to its nature. > > Python is a dynamically typed language. Its variables don't have types, > > only its objects.

Re: Question on ABC classes

2020-10-29 Thread Julio Di Egidio
On Sunday, 25 October 2020 20:55:26 UTC+1, Peter J. Holzer wrote: > On 2020-10-22 23:35:21 -0700, Julio Di Egidio wrote: > > On Friday, 23 October 2020 07:36:39 UTC+2, Greg Ewing wrote: > > > On 23/10/20 2:13 pm, Julio Di Egidio wrote: > > > > I am now thinking whether I could achieve the "standa

Re: Question on ABC classes

2020-10-26 Thread Dieter Maurer
Peter J. Holzer wrote at 2020-10-25 20:48 +0100: >On 2020-10-22 23:35:21 -0700, Julio Di Egidio wrote: > ... >> and the whole lot, indeed why even subclass ABC? You often have the case that a base class can implement a lot of functionality based on a few methods defined by derived

Re: Question on ABC classes

2020-10-25 Thread Peter J. Holzer
On 2020-10-22 23:35:21 -0700, Julio Di Egidio wrote: > On Friday, 23 October 2020 07:36:39 UTC+2, Greg Ewing wrote: > > On 23/10/20 2:13 pm, Julio Di Egidio wrote: > > > I am now thinking whether I could achieve the "standard" > > > behaviour via another approach, say with decorators, somehow > >

RE: Question on ABC classes

2020-10-23 Thread Schachner, Joseph
I'm a C++ programmer and Python programmer as well. Python classes are not exactly like C++ classes. If you define a class where every method has an implementation, then it really isn't abstract. It can be instantiated. You can force it to be abstract by doing from abc import A

Re: Question on ABC classes

2020-10-22 Thread Julio Di Egidio
On Friday, 23 October 2020 07:36:39 UTC+2, Greg Ewing wrote: > On 23/10/20 2:13 pm, Julio Di Egidio wrote: > > I am now thinking whether I could achieve the "standard" > > behaviour via another approach, say with decorators, somehow > > intercepting calls to __new__... maybe. > > I'm inclined to

Re: Question on ABC classes

2020-10-22 Thread Greg Ewing
On 23/10/20 2:13 pm, Julio Di Egidio wrote: I am now thinking whether I could achieve the "standard" behaviour via another approach, say with decorators, somehow intercepting calls to __new__... maybe. I'm inclined to step back and ask -- why do you care about this? Would it actually do any ha

Re: Question on ABC classes

2020-10-22 Thread Julio Di Egidio
): >pass > > Then subclass from that: > >class MoreConcrete(Concrete): >pass > > If you do a > >issubclass(, ABC) > > you'll get > >True Ah, right, that's the point I was missing: how to tell the compiler when a mor

Re: Question on ABC classes

2020-10-22 Thread Ethan Furman
#x27;s say you subclass from ABC: class Abstract(ABC): pass Then you subclass from that: class Concrete(Abstract): pass Then subclass from that: class MoreConcrete(Concrete): pass If you do a issubclass(, ABC) you'll get True The idea behind abstract

Re: Question on ABC classes

2020-10-22 Thread Marco Sulla
On Thu, 22 Oct 2020 at 22:09, Marco Sulla wrote: > Not sure because I never tried or needed, but if no @abstractsomething in > A is defined and your B class is a subclass of A, B should be an abstract > class, not a concrete class. > Now I'm sure: >>> from abc import ABC, abstractmethod >>> cla

Re: Question on ABC classes

2020-10-22 Thread Marco Sulla
On Thu, 22 Oct 2020 at 18:31, Julio Di Egidio wrote: > why > only if there are abstract methods defined in an ABC > class is instantiation disallowed? > Not sure because I never tried or needed, but if no @abstractsomething in A is defined and your B class is a subclass of A, B should be an abst

Question on ABC classes

2020-10-22 Thread Julio Di Egidio
OO language the class would be not instantiable, period, since it's "abstract". But this is not so in Python, to the point that, also for uniformity, I am feeling compelled to define an @abstractmethod __init__ in my ABC classes, whether they need one or not, and whether there are

Re: Are instances of user-defined classes mutable?

2020-08-07 Thread Richard Damon
On 8/6/20 10:53 PM, ZHAOWANCHENG wrote: > So instances of user-defined classes are immutable by default? > Or the description of "if a tuple contains any mutable object either > directly or indirectly, it cannot be used as a key." in the document > is not completely corr

Re: Are instances of user-defined classes mutable?

2020-08-07 Thread Mats Wichmann
On 8/6/20 8:53 PM, ZHAOWANCHENG wrote: > So instances of user-defined classes are immutable by default? No, they're clealry mutable. > Or the description of "if a tuple contains any mutable object either directly > or indirectly, it cannot be used as a key."

Re:Re: Are instances of user-defined classes mutable?

2020-08-06 Thread ZHAOWANCHENG
me = mycls() >>> >>> me.a = 2 # mutable? >>> >>> {(1, me): 'mycls'} >>> {(1, <__main__.mycls object at 0x022824DAD668>): 'mycls'} >>> >>> >>> >>> >>> So are

Re: Are instances of user-defined classes mutable?

2020-08-06 Thread David Lowry-Duda
aced into a tuple that as a key of a dict: > >>> class mycls(object): > ... a = 1 > ... > >>> me = mycls() > >>> me.a = 2 # mutable? > >>> {(1, me): 'mycls'} > {(1, <__main__.mycls object at 0x000

Re: Are instances of user-defined classes mutable?

2020-08-06 Thread Richard Damon
): 'mycls'} >>      {(1, <__main__.mycls object at 0x022824DAD668>): 'mycls'} >> >>> >> >> >> So are instances of user-defined classes mutable or immutable? >> > user class instances are clearly mutable, and in my python

Re: Are instances of user-defined classes mutable?

2020-08-06 Thread Ethan Furman
On 8/6/20 7:40 AM, Robin Becker wrote: On 06/08/2020 05:17, ZHAOWANCHENG wrote: So are instances of user-defined classes mutable or immutable? user class instances are clearly mutable, and in my python 3.8 you can do horrid things like this > > [snip buggy/incorrect uses of __hash__

Re: Are instances of user-defined classes mutable?

2020-08-06 Thread Richard Damon
hat as a key of a dict: > >>> class mycls(object): > ... a = 1 > ... > >>> me = mycls() > >>> me.a = 2 # mutable? > >>> {(1, me): 'mycls'} > {(1, <__main__.mycls object at 0x022824DAD668>):

Re: Are instances of user-defined classes mutable?

2020-08-06 Thread Robin Becker
of a dict: >>> class mycls(object): ... a = 1 ... >>> me = mycls() >>> me.a = 2 # mutable? >>> {(1, me): 'mycls'} {(1, <__main__.mycls object at 0x022824DAD668>): 'mycls'} >>> So are i

Are instances of user-defined classes mutable?

2020-08-06 Thread ZHAOWANCHENG
: ... a = 1 ... >>> me = mycls() >>> me.a = 2 # mutable? >>> {(1, me): 'mycls'} {(1, <__main__.mycls object at 0x022824DAD668>): 'mycls'} >>> So are instances of user-defined classes mutable or immutable? -- https://mail.python.org/mailman/listinfo/python-list

Re: using classes

2020-03-13 Thread Pieter van Oostrum
joseph pareti wrote: > one more question. In the code below, there are 2 init() methods, one for > the class 'Fahrzeug' and > one for the class 'PKW'. > The program works when I instantiate the class as: > > fiat = PKW("Fiat Marea",50,0) > > but it fails if I say: > > fiat = PKW("Fia

Re: using classes

2020-03-13 Thread Peter J. Holzer
On 2020-03-13 09:46:29 +0100, joseph pareti wrote: > The program works when I instantiate the class as: > > fiat = PKW("Fiat Marea",50,0) > > but it fails if I say: > > *fiat = PKW("Fiat Marea",50,0,1)* The __init__ method of PKW has this signature: > def __init__(self, bez, ge, ins): You

Re: using classes

2020-03-13 Thread joseph pareti
one more question. In the code below, there are 2 init() methods, one for the class 'Fahrzeug' and one for the class 'PKW'. The program works when I instantiate the class as: fiat = PKW("Fiat Marea",50,0) but it fails if I say: *fiat = PKW("Fiat Marea",50,0,1)* *Traceback (most recent call l

Re: using classes

2020-03-12 Thread Pieter van Oostrum
joseph pareti writes: > thank you, that fixes it. I also noticed that both statements work: > > super(PKW, self).__init__(bez,ge) > > or > >super().__init__(bez,ge) The first is the required Python 2 calling (at least the first argument is required). The second way can be used

Re: using classes

2020-03-12 Thread Barry
> On 12 Mar 2020, at 14:28, joseph pareti wrote: > > thank you, that fixes it. I also noticed that both statements work: > > super(PKW, self).__init__(bez,ge) This form is for python 2 compatibility. > > or > > super().__init__(bez,ge) This is the python 3 way. If you do not

Re: using classes

2020-03-12 Thread joseph pareti
thank you, that fixes it. I also noticed that both statements work: super(PKW, self).__init__(bez,ge) or super().__init__(bez,ge) Am Do., 12. März 2020 um 12:58 Uhr schrieb MRAB : > On 2020-03-12 10:54, joseph pareti wrote: > > The following code that uses a class 'Fahrzeug' an

Re: using classes

2020-03-12 Thread MRAB
On 2020-03-12 10:54, joseph pareti wrote: The following code that uses a class 'Fahrzeug' and an inherited class 'PKW' runs correctly. However, if I use the 'super ' statement in in the PKW class, it ends with the following error message: *Traceback (most recent call last): File "erben_a.py",

using classes

2020-03-12 Thread joseph pareti
The following code that uses a class 'Fahrzeug' and an inherited class 'PKW' runs correctly. However, if I use the 'super ' statement in in the PKW class, it ends with the following error message: *Traceback (most recent call last): File "erben_a.py", line 19, in fiat = PKW("Fiat Marea",

Re: Nesting Custom Errors in Classes

2019-07-23 Thread Cameron Simpson
y horse for that matter) I'm pleased at the (lack of negative) response to my allied question about nested classes, which would solve the original problem) There's nothing "wrong" with it. It is uncommon. But like a lot of things, the value (or cost/pitfalls) com

Re: Nesting Custom Errors in Classes

2019-07-23 Thread DL Neil
r) I'm pleased at the (lack of negative) response to my allied question about nested classes, which would solve the original problem) -- Regards =dn -- https://mail.python.org/mailman/listinfo/python-list

Re: Nesting Custom Errors in Classes

2019-07-23 Thread Cameron Simpson
The whole point of object oriented programme is to present things with the same external API but different internal implementations, or managing a different thing with common characteristics. I have use nested classes when the nested class is strongly associated with the enclosing class,

Re: Nesting Custom Errors in Classes

2019-07-23 Thread DL Neil
On 23/07/19 11:55 PM, Cameron Simpson wrote: On 23Jul2019 14:54, DL Neil wrote: Do you use nested classes? Python manages nested classes. I've NEVER seen such 'in the wild'. (but perhaps I lead a sheltered life?) So sheltered :-) Well, over here there aren't the ve

Re: Nesting Custom Errors in Classes

2019-07-23 Thread Rob Gaddi
On 7/22/19 7:54 PM, DL Neil wrote: Do you use nested classes? [following-on from the earlier, "Namespaces: memory vs 'pollution'" discussion thread, wherein a certain 'someone' remembered to from ... import ... as ... an 'action' class but forgot to al

Re: Nesting Custom Errors in Classes

2019-07-23 Thread Cameron Simpson
On 23Jul2019 14:54, DL Neil wrote: Do you use nested classes? Python manages nested classes. I've NEVER seen such 'in the wild'. (but perhaps I lead a sheltered life?) So sheltered :-) In my experience it's uncommon. I've done it a few times. "Nested" c

Nesting Custom Errors in Classes

2019-07-22 Thread DL Neil
Do you use nested classes? [following-on from the earlier, "Namespaces: memory vs 'pollution'" discussion thread, wherein a certain 'someone' remembered to from ... import ... as ... an 'action' class but forgot to also import the related custom error

Re: Embedding classes' names

2019-07-17 Thread DL Neil
On 16/07/19 10:57 PM, Cameron Simpson wrote: On 16Jul2019 10:20, Chris Angelico wrote: On Tue, Jul 16, 2019 at 10:17 AM DL Neil wrote: When used, do you embed a class's name within its own code, as a literal? [...] So, what about other situations where one might need to access the class's o

Re: Embedding classes' names

2019-07-16 Thread Cameron Simpson
On 16Jul2019 10:20, Chris Angelico wrote: On Tue, Jul 16, 2019 at 10:17 AM DL Neil wrote: When used, do you embed a class's name within its own code, as a literal? [...] So, what about other situations where one might need to access the class's own name or that of its/a super-class? eg clas

Re: Embedding classes' names

2019-07-15 Thread Chris Angelico
> >>> > > One of the answers recommended super() [agreed!] in order to avoid > embedding "C1" into the code. The explanation: in case the name of the > parent class is ever changed. > > Which is eminently reasonable (remember, the parent class may be in a &

Embedding classes' names

2019-07-15 Thread DL Neil
embedding "C1" into the code. The explanation: in case the name of the parent class is ever changed. Which is eminently reasonable (remember, the parent class may be in a separate file, and thus few "cues" to remember to inspect and amend sub-classes' code!) So, what

Re: Python best practice instantiating classes in app

2019-04-29 Thread DL Neil
Dave, On 30/04/19 7:36 AM, Dave wrote: On 4/29/19 3:26 PM, Terry Reedy wrote: On 4/29/2019 1:38 PM, Dave wrote: As apps get more complex we add modules, or Python files, to organize things.  One problem I have is a couple of data classes (list of dictionary objects) in a few modules that

Re: Python best practice instantiating classes in app

2019-04-29 Thread Dave
On 4/29/19 3:26 PM, Terry Reedy wrote: On 4/29/2019 1:38 PM, Dave wrote: As apps get more complex we add modules, or Python files, to organize things.  One problem I have is a couple of data classes (list of dictionary objects) in a few modules that are used in a number of the other modules

Re: Python best practice instantiating classes in app

2019-04-29 Thread Terry Reedy
On 4/29/2019 1:38 PM, Dave wrote: As apps get more complex we add modules, or Python files, to organize things.  One problem I have is a couple of data classes (list of dictionary objects) in a few modules that are used in a number of the other modules.  For example a list of meter reading

Python best practice instantiating classes in app

2019-04-29 Thread Dave
As apps get more complex we add modules, or Python files, to organize things. One problem I have is a couple of data classes (list of dictionary objects) in a few modules that are used in a number of the other modules. For example a list of meter reading dictionaries in one module is used by

Re: Quirk difference between classes and functions

2019-02-27 Thread Peter J. Holzer
On 2019-02-27 12:34:37 -0500, Dennis Lee Bieber wrote: > On Tue, 26 Feb 2019 19:15:16 -0800 (PST), jf...@ms4.hinet.net declaimed the > following: > > >So, may I say that the Python compiler is a multi-pass one? > > No... that is implementation dependent... True, but > The common Pyt

Re: Quirk difference between classes and functions

2019-02-27 Thread jfong
jf...@ms4.hinet.net於 2019年2月26日星期二 UTC+8下午4時46分04秒寫道: > ast於 2019年2月26日星期二 UTC+8上午12時25分40秒寫道: > > Hello > > > > I noticed a quirk difference between classes and functions > > > > >>> x=0 > > >>> > > >>> cla

Re: Quirk difference between classes and functions

2019-02-26 Thread jfong
Chris Angelico於 2019年2月27日星期三 UTC+8上午11時29分04秒寫道: > On Wed, Feb 27, 2019 at 2:21 PM wrote: > > > > Chris Angelico於 2019年2月27日星期三 UTC+8上午9時25分11秒寫道: > > > On Wed, Feb 27, 2019 at 12:21 PM wrote: > > > > > > > > Gregory Ewing at 2019/2/27 AM 5:26:49 wrote: > > > > > Thomas Jollans wrote: > > > > >

Re: Quirk difference between classes and functions

2019-02-26 Thread Chris Angelico
On Wed, Feb 27, 2019 at 2:21 PM wrote: > > Chris Angelico於 2019年2月27日星期三 UTC+8上午9時25分11秒寫道: > > On Wed, Feb 27, 2019 at 12:21 PM wrote: > > > > > > Gregory Ewing at 2019/2/27 AM 5:26:49 wrote: > > > > Thomas Jollans wrote: > > > > > I imagine there's a justification for the difference in behaviou

Re: Quirk difference between classes and functions

2019-02-26 Thread jfong
Chris Angelico於 2019年2月27日星期三 UTC+8上午9時25分11秒寫道: > On Wed, Feb 27, 2019 at 12:21 PM wrote: > > > > Gregory Ewing at 2019/2/27 AM 5:26:49 wrote: > > > Thomas Jollans wrote: > > > > I imagine there's a justification for the difference in behaviour to do > > > > with the fact that the body of a class

Re: Quirk difference between classes and functions

2019-02-26 Thread Chris Angelico
On Wed, Feb 27, 2019 at 12:21 PM wrote: > > Gregory Ewing at 2019/2/27 AM 5:26:49 wrote: > > Thomas Jollans wrote: > > > I imagine there's a justification for the difference in behaviour to do > > > with the fact that the body of a class is only ever executed once, while > > > the body of a functi

Re: Quirk difference between classes and functions

2019-02-26 Thread eryk sun
On 2/26/19, Gregory Ewing wrote: > Thomas Jollans wrote: >> I imagine there's a justification for the difference in behaviour to do >> with the fact that the body of a class is only ever executed once, while >> the body of a function is executed multiple times. > > I suspect there isn't any deep r

Re: Quirk difference between classes and functions

2019-02-26 Thread jfong
Gregory Ewing at 2019/2/27 AM 5:26:49 wrote: > Thomas Jollans wrote: > > I imagine there's a justification for the difference in behaviour to do > > with the fact that the body of a class is only ever executed once, while > > the body of a function is executed multiple times. > > I suspect there i

RE: Quirk difference between classes and functions

2019-02-26 Thread Steve
#x27;s 117 bugs in the code. -Original Message- From: Python-list On Behalf Of Gregory Ewing Sent: Tuesday, February 26, 2019 4:27 PM To: python-list@python.org Subject: Re: Quirk difference between classes and functions Thomas Jollans wrote: > I imagine there's a justification for

Re: Quirk difference between classes and functions

2019-02-26 Thread Gregory Ewing
Thomas Jollans wrote: I imagine there's a justification for the difference in behaviour to do with the fact that the body of a class is only ever executed once, while the body of a function is executed multiple times. I suspect there isn't any deep reason for it, rather it's just something that

Re: Quirk difference between classes and functions

2019-02-26 Thread Thomas Jollans
On 25/02/2019 21.15, Chris Angelico wrote: > On Tue, Feb 26, 2019 at 6:58 AM DL Neil > wrote: >> >> On 26/02/19 5:25 AM, ast wrote: >>> I noticed a quirk difference between classes and functions >>> >>> x=0 >>> >>> class Test:

Re: Quirk difference between classes and functions

2019-02-26 Thread jfong
ast於 2019年2月26日星期二 UTC+8上午12時25分40秒寫道: > Hello > > I noticed a quirk difference between classes and functions > > >>> x=0 > >>> > >>> class Test: > x = x+1 > print(x) > x = x+1 > print(x) >

Re: Quirk difference between classes and functions

2019-02-25 Thread Chris Angelico
On Tue, Feb 26, 2019 at 5:06 PM Gregory Ewing wrote: > > Chris Angelico wrote: > > Classes and functions behave differently. Inside a function, a name is > > local if it's ever assigned to; but in a class, this is not the case. > > Actually, it is. Assigning to a

Re: Quirk difference between classes and functions

2019-02-25 Thread Gregory Ewing
Chris Angelico wrote: Classes and functions behave differently. Inside a function, a name is local if it's ever assigned to; but in a class, this is not the case. Actually, it is. Assigning to a name in a class body makes it part of the class namespace, which is the local namespace at the

Re: Quirk difference between classes and functions

2019-02-25 Thread Chris Angelico
On Tue, Feb 26, 2019 at 6:58 AM DL Neil wrote: > > On 26/02/19 5:25 AM, ast wrote: > > I noticed a quirk difference between classes and functions > > >>> x=0 > > >>> class Test: > > x = x+1 > > print(x) > >

Re: Quirk difference between classes and functions

2019-02-25 Thread DL Neil
On 26/02/19 5:25 AM, ast wrote: I noticed a quirk difference between classes and functions >>> x=0 >>> class Test:     x = x+1     print(x)     x = x+1     print(x) ... Previous code doesn't generate any errors. x at the right of = in first "

Quirk difference between classes and functions

2019-02-25 Thread ast
Hello I noticed a quirk difference between classes and functions >>> x=0 >>> >>> class Test: x = x+1 print(x) x = x+1 print(x) 1 2 >>> print(x) 0 Previous code doesn't generate any errors. x at the right of = in fi

Re: Ask for help about class variable scope (Re: Why doesn't a dictionary work in classes?)

2018-12-28 Thread jfong
jf...@ms4.hinet.net於 2018年12月28日星期五 UTC+8下午4時04分07秒寫道: > eryk sun at 2018/12/27 UTC+8 PM 6:58:33 wrote: > > On 12/27/18, jf...@ms4.hinet.net wrote: > > > > > > I still don't get it. When I change it to using list comprehension, the > > > problem is still there. (it now has no late-binding variable

Re: Ask for help about class variable scope (Re: Why doesn't a dictionary work in classes?)

2018-12-28 Thread jfong
eryk sun at 2018/12/27 UTC+8 PM 6:58:33 wrote: > On 12/27/18, jf...@ms4.hinet.net wrote: > > > > I still don't get it. When I change it to using list comprehension, the > > problem is still there. (it now has no late-binding variable, right? :-) > > > class Too: > > ... XS = [15, 15, 15,

Re: Ask for help about class variable scope (Re: Why doesn't a dictionary work in classes?)

2018-12-27 Thread Chris Angelico
On Fri, Dec 28, 2018 at 8:47 AM eryk sun wrote: > > On 12/27/18, Chris Angelico wrote: > > > > Class scope is special, and a generator expression within that class > > scope is special too. There have been proposals to make these kinds of > > things less special, but the most important thing to r

Re: Ask for help about class variable scope (Re: Why doesn't a dictionary work in classes?)

2018-12-27 Thread eryk sun
On 12/27/18, Chris Angelico wrote: > > Class scope is special, and a generator expression within that class > scope is special too. There have been proposals to make these kinds of > things less special, but the most important thing to remember is that > when you create a generator expression, it

Re: Ask for help about class variable scope (Re: Why doesn't a dictionary work in classes?)

2018-12-27 Thread Chris Angelico
On Fri, Dec 28, 2018 at 3:31 AM Ian Kelly wrote: > > On Wed, Dec 26, 2018 at 11:21 PM Chris Angelico wrote: > > > > On Thu, Dec 27, 2018 at 1:56 PM wrote: > > > > > > I saw the code below at stackoverflow. I have a little idea about the > > > scope of a class, and list comprehension and generat

Re: Ask for help about class variable scope (Re: Why doesn't a dictionary work in classes?)

2018-12-27 Thread Ian Kelly
On Wed, Dec 26, 2018 at 11:21 PM Chris Angelico wrote: > > On Thu, Dec 27, 2018 at 1:56 PM wrote: > > > > I saw the code below at stackoverflow. I have a little idea about the scope > > of a class, and list comprehension and generator expressions, but still > > can't figure out why Z4 works and

Re: Ask for help about class variable scope (Re: Why doesn't a dictionary work in classes?)

2018-12-27 Thread eryk sun
On 12/27/18, jf...@ms4.hinet.net wrote: > > I still don't get it. When I change it to using list comprehension, the > problem is still there. (it now has no late-binding variable, right? :-) > class Too: > ... XS = [15, 15, 15, 15] > ... Z4 = [val for val in XS] > ... Z5 = [XS[0]

  1   2   3   4   5   6   7   8   9   10   >