Re: an oop question

2022-10-30 Thread Chris Angelico
On Mon, 31 Oct 2022 at 14:38, Julieta Shem wrote: > > Chris Angelico writes: > > > The most straight-forward way to represent this concept in an > > object-oriented way is subclassing. > > > > class Stack: > > ... # put whatever code is common here > > > > class Empty(Stack): > > ... #

Re: Weired behaviour - The slice of empty string not return an error

2022-10-30 Thread dn
On 31/10/2022 03.59, Yassine Nasri wrote: PS: The ''[::] should return an error logically. Le dim. 30 oct. 2022 à 15:57, Yassine Nasri a écrit : Hello, len('') # => 0''[0]# => error''[::] # => [::] # <=> ''[0:len(''):1] the syntax of slice: slice(start, end, step) The start

Re: an oop question

2022-10-30 Thread Julieta Shem
Chris Angelico writes: > On Mon, 31 Oct 2022 at 09:05, Julieta Shem wrote: >> >> Julieta Shem writes: >> >> [...] >> >> >> . If you should, however, be talking about the new "type hints": >> >> These are static and have "Union", for example, "Union[int, str]" >> >> or "int | str". >> >

Re: Weired behaviour - The slice of empty string not return an error

2022-10-30 Thread MRAB
On 2022-10-30 14:57, Yassine Nasri wrote: Hello, len('') # => 0''[0]# => error''[::] # => [::] # <=> ''[0:len(''):1] the syntax of slice: slice(start, end, step) The start in ''[::] equivalent at index 0 of the '' Since the index 0 of '' returns an error. The ''[::] should not

Re: an oop question

2022-10-30 Thread dn
On 31/10/2022 09.22, Stefan Ram wrote: Giorgio Pastore writes: You may find useful to learn about the possibilities of using Python tools to implement a stack data structure and its manipulation methods. A good introduction is at https://realpython.com/how-to-implement-python-stack/ I

Re: Fwd: A typing question

2022-10-30 Thread dn
On 31/10/2022 11.44, Chris Angelico wrote: On Mon, 31 Oct 2022 at 09:39, dn wrote: On 31/10/2022 06.06, Stefan Ram wrote: Paulo da Silva writes: Is there anything to do without loosing my script structure and usual practice? to lose (losing): to stop having something to loose

Re: an oop question

2022-10-30 Thread Weatherby,Gerard
I don’t understand your implementation enough to comment specifically. What’s the definition of Pair? (i.e. what methods and public attributes does it have?) (I manage to escape Lisp as an undergrad) To answer your question generally, Union’s are not OO. If you want Pair and Stack to have the

[Python-announce] Austin -- CPython frame stack sampler v3.4 is now available

2022-10-30 Thread Gabriele Tornetta
I am delighted to announce the 3.4 release of Austin. If you haven't heard of Austin before, it is an open-source frame stack sampler for CPython, distributed under the GPLv3 license. It can be used to obtain statistical profiling data out of a running Python application without a single line

Re: Fwd: A typing question

2022-10-30 Thread Chris Angelico
On Mon, 31 Oct 2022 at 09:39, dn wrote: > > On 31/10/2022 06.06, Stefan Ram wrote: > > Paulo da Silva writes: > >> Is there anything to do without loosing my script structure and usual > >> practice? > > > >to lose (losing): to stop having something > >to loose (loosing): to let or make

Re: Fwd: A typing question

2022-10-30 Thread dn
On 31/10/2022 06.06, Stefan Ram wrote: Paulo da Silva writes: Is there anything to do without loosing my script structure and usual practice? to lose (losing): to stop having something to loose (loosing): to let or make loose (see next line) loose (adj.): not firmly

Re: an oop question

2022-10-30 Thread Chris Angelico
On Mon, 31 Oct 2022 at 09:05, Julieta Shem wrote: > > Julieta Shem writes: > > [...] > > >> . If you should, however, be talking about the new "type hints": > >> These are static and have "Union", for example, "Union[int, str]" > >> or "int | str". > > > > I ended up locating such features

Re: Fwd: A typing question

2022-10-30 Thread dn
On 30/10/2022 17.48, Paulo da Silva wrote: Às 02:32 de 30/10/22, dn escreveu: On 30/10/2022 11.59, Paulo da Silva wrote: Solution (below) will not work if the mention of Foos in GLOBALS is a forward-reference. Either move GLOBALS to suit, or surround "Foos" with quotes. This is the problem

Re: an oop question

2022-10-30 Thread Giorgio Pastore
Il 30/10/22 15:54, Julieta Shem ha scritto: r...@zedat.fu-berlin.de (Stefan Ram) writes: Julieta Shem writes: My desire seems to imply that I need a union-like data structure. You only need to worry about such things in languages with static typing. For example, to have a function

Re: Fwd: A typing question

2022-10-30 Thread Paulo da Silva
Às 17:06 de 30/10/22, Stefan Ram escreveu: Paulo da Silva writes: Is there anything to do without loosing my script structure and usual practice? to lose (losing): to stop having something to loose (loosing): to let or make loose (see next line) loose (adj.): not firmly

Re: an oop question

2022-10-30 Thread Julieta Shem
Julieta Shem writes: [...] >> . If you should, however, be talking about the new "type hints": >> These are static and have "Union", for example, "Union[int, str]" >> or "int | str". > > I ended up locating such features of the language in the documentation, > but I actually am not

Re: Weired behaviour - The slice of empty string not return an error

2022-10-30 Thread Yassine Nasri
PS: The ''[::] should return an error logically. Le dim. 30 oct. 2022 à 15:57, Yassine Nasri a écrit : > Hello, > > len('') # => 0''[0]# => error''[::] # => [::] # <=> > ''[0:len(''):1] > > the syntax of slice: > > slice(start, end, step) > > The start in ''[::] equivalent at

Re: Fwd: A typing question

2022-10-30 Thread Paulo da Silva
Às 22:34 de 29/10/22, dn escreveu: Out of interest, tested snippet in PyCharm, cf native-mypy. It flags the original:     GLOBALS.foos: Optional[Foos]=Foos() but not the fall-back:     GLOBALS.foos=Foos() Must admit, the first query coming to mind was: why is the typing taking place at

Weired behaviour - The slice of empty string not return an error

2022-10-30 Thread Yassine Nasri
Hello, len('') # => 0''[0]# => error''[::] # => [::] # <=> ''[0:len(''):1] the syntax of slice: slice(start, end, step) The start in ''[::] equivalent at index 0 of the '' Since the index 0 of '' returns an error. The ''[::] should not return an error logically. Best regards

Re: Fwd: A typing question

2022-10-30 Thread Paulo da Silva
Às 10:26 de 30/10/22, Peter J. Holzer escreveu: On 2022-10-29 23:59:44 +0100, Paulo da Silva wrote: Às 22:34 de 29/10/22, dn escreveu: Solution (below) will not work if the mention of Foos in GLOBALS is a forward-reference. Either move GLOBALS to suit, or surround "Foos" with quotes.

Re: an oop question

2022-10-30 Thread Julieta Shem
r...@zedat.fu-berlin.de (Stefan Ram) writes: > Julieta Shem writes: >>My desire seems to imply that I need a union-like data structure. > > You only need to worry about such things in languages with > static typing. For example, to have a function that can > sometimes return an int value

an oop question

2022-10-30 Thread Julieta Shem
I have a question about a particular case I'm working on. I'm studying OOP. To ask the question, I'm going to have to introduce you my context here, so you'll need to bear with me. If you'd like to see the question right away, go to the section ``My difficulty in encapsulating a union''. (*)

Re: A typing question

2022-10-30 Thread Paulo da Silva
Às 01:14 de 30/10/22, Thomas Passin escreveu: On 10/29/2022 1:45 PM, Paulo da Silva wrote: Hi! Consider this simple script ... ___ from typing import List, Optional class GLOBALS: foos=None class Foo: def __init__(self): pass class Foos: Foos:

Re: Fwd: A typing question

2022-10-30 Thread Paulo da Silva
Às 02:32 de 30/10/22, dn escreveu: On 30/10/2022 11.59, Paulo da Silva wrote: Solution (below) will not work if the mention of Foos in GLOBALS is a forward-reference. Either move GLOBALS to suit, or surround "Foos" with quotes. This is the problem for me. So far, without typing, I used to have

Re: Fwd: A typing question

2022-10-30 Thread Peter Otten
On 30/10/2022 14:37, Peter J. Holzer wrote: On 2022-10-30 09:23:27 -0400, Thomas Passin wrote: On 10/30/2022 6:26 AM, Peter J. Holzer wrote: On 2022-10-29 23:59:44 +0100, Paulo da Silva wrote: The funny thing is that if I replace foos by Foos it works because it gets known by the initial

Re: Fwd: A typing question

2022-10-30 Thread Peter J. Holzer
On 2022-10-30 09:23:27 -0400, Thomas Passin wrote: > On 10/30/2022 6:26 AM, Peter J. Holzer wrote: > > On 2022-10-29 23:59:44 +0100, Paulo da Silva wrote: > > > The funny thing is that if I replace foos by Foos it works because it gets > > > known by the initial initialization :-) ! > > > > > >

Re: Fwd: A typing question

2022-10-30 Thread Thomas Passin
On 10/30/2022 6:26 AM, Peter J. Holzer wrote: On 2022-10-29 23:59:44 +0100, Paulo da Silva wrote: Às 22:34 de 29/10/22, dn escreveu: Solution (below) will not work if the mention of Foos in GLOBALS is a forward-reference. Either move GLOBALS to suit, or surround "Foos" with quotes.

Re: Fwd: A typing question

2022-10-30 Thread Peter J. Holzer
On 2022-10-29 23:59:44 +0100, Paulo da Silva wrote: > Às 22:34 de 29/10/22, dn escreveu: > > Solution (below) will not work if the mention of Foos in GLOBALS is a > > forward-reference. > > Either move GLOBALS to suit, or surround "Foos" with quotes.

Re: A typing question

2022-10-30 Thread Peter J. Holzer
On 2022-10-29 20:14:12 -0400, Thomas Passin wrote: > I don't understand > > class Foos: > Foos: List[Foo]=[] > > If "Foos" is supposed to be a class attribute, then it cannot have the same > name as the class. Why not? They are in different namespaces. #v+ #!/usr/bin/python3 class Foos: