Re: typing: property/setter and lists? [RESOLVED ERRATA]

2022-11-04 Thread dn

On 04/11/2022 07.50, Chris Angelico wrote:

On Fri, 4 Nov 2022 at 05:48, Paulo da Silva
 wrote:


Às 05:32 de 03/11/22, Paulo da Silva escreveu:

Às 03:24 de 03/11/22, Paulo da Silva escreveu:

Hi!

And a typing problem again!!!
___
class C:
  def __init__(self):
  self.__foos=5*[0]

  @property
  def foos(self) -> list[int]:
  return self.__foos

  @foos.setter
  def foos(self,v: int):
  self.__foos=[v for __i in self.__foos]

c=C()
c.foos=5
print(c.foos)
___

mypy gives the following error:
error: Incompatible types in assignment (expression has type "int",
variable has type "List[int]")

How do I turn around this?


Changing def foos(self) -> list[int]:  to
   def foos(self) -> Union[list[int]]:

I meant, of course,
def foos(self) -> Union[list[int],int]:



Ohhh! I thought this was triggering a strange quirk of the checker in
some way...



Yes, these personal styles (?quirks) are off-putting to others.

Plus "_" means (more or less) "not used anymore"
and for most of us, a weak-identifier name such as "i" is indeed "an 
indexer/counter/... "
Accordingly, the question becomes: why not follow the crowd - unless you 
tell me that this is a team/company convention?


...and whilst I'm griping,
"To help us to help you please copy-paste the *exact* message"
has been followed by:
"I'm sorry. A bad transposition of the text."

copy-paste for the win!
(and to keep others happy to spend their voluntary time helping you - 
more working-with-the-team thinking to consider - please)

--
Regards,
=dn
--
https://mail.python.org/mailman/listinfo/python-list


Re: Problems with IDLE in Windows 8.1 and installer x86 Version 3.10.8

2022-11-04 Thread darkstone
Yes, there is always the message “modified successfull”, “installed 
sucessfully”, but IDLE does’t start. I tried it with the newer Version, too. 
Ist 3.11.0 for 32 bit, but it also doesn’t work. Do you have other suggetions, 
that it works?







Von: Eryk Sun
Gesendet: ‎Donnerstag‎, ‎3‎. ‎November‎ ‎2022 ‎22‎:‎50
An: [email protected]
Cc: [email protected]





On 11/3/22, [email protected]  wrote:
> Is there a reason, why it is not installed? Its the same check mark in the
> installer like IDLE…

Did you try what I suggested? Modify the installation to remove the
tkinter/IDLE component. Then modify it again to select the component
to be reinstalled. Also, try to repair the installation. This may
reset any DLLs or extension modules that were missing or that were the
wrong version.

Ignore the suggestion from Nithish to install tkinter via pip. tkinter
is part of the standard library and cannot be installed via pip. There
is no tkinter package on the Python package index (pypi.org).
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: an oop question

2022-11-04 Thread Greg Ewing

On 4/11/22 1:29 am, Julieta Shem wrote:

Perhaps I can reduce the
class Pair to just being a pair as we know it, made of two things, then
we create a class called Sequence, which is really a composition of
Pairs, comes with a length method and we derive Stack from it.


That sounds better. But be careful -- a Sequence class would
probably be expected to have methods for e.g. inserting and
removing things in the middle, which you might not want to
allow for a Stack.

--
Greg
--
https://mail.python.org/mailman/listinfo/python-list


Re: an oop question

2022-11-04 Thread Greg Ewing

On 4/11/22 12:50 am, Chris Angelico wrote:

In Python, everything is an object. Doesn't that equally mean that
Python is purely OOP?


Depends on what you mean by "purely oop". To me it suggests a
language in which dynamically-dispatched methods are the only
form of code. Python is not one of those, because it has
stand-alone functions.

I'm not sure I know of *any* language that is purely oop in
that sense. Smalltalk probably comes the closest, but then its
code blocks are essentially lexically-scoped anonymous functions.
You *could* write Smalltalk code in a procedural style by
assigning a bunch of code blocks to names and calling them like
functions. Not that there would be any reason to do that other
than as a party trick.

Java looks like it's fairly purely OO at first glance, but it
has static methods, which are really stand-alone functions by
another name. Also it has some primitive types such as ints
and floats that don't behave in an OO way at all.

--
Greg
--
https://mail.python.org/mailman/listinfo/python-list


Re: an oop question

2022-11-04 Thread Greg Ewing

[email protected] (Stefan Ram) writes [that Barbara Liskov said]:


|If for each object o1 of type S there is an object o2 of
|type T such that for all programs P defined in terms of T,
|the behavior of P is unchanged when o1 is substituted for o2
|then S is a subtype of T.


That seems overly restrictive, because it wouldn't allow S to
override a method of T and make it do something different --
which we do all the time in practice.


Class contracts must hold for subclasses.


That sounds like a much better way of saying it!

--
Greg
--
https://mail.python.org/mailman/listinfo/python-list


Re: an oop question

2022-11-04 Thread Greg Ewing

On 4/11/22 7:51 am, Julieta Shem wrote:


(The empty documentation seems to satisfy the principle.)


All the more reason to document your classes!

More seriously, there's always at least a (possibly fuzzily) implied
contract, because of the names you choose for things if nothing else.

--
Greg
--
https://mail.python.org/mailman/listinfo/python-list


Re: an oop question

2022-11-04 Thread Chris Angelico
On Sat, 5 Nov 2022 at 02:21, Greg Ewing  wrote:
>
> > [email protected] (Stefan Ram) writes [that Barbara Liskov said]:
> >
> >> |If for each object o1 of type S there is an object o2 of
> >> |type T such that for all programs P defined in terms of T,
> >> |the behavior of P is unchanged when o1 is substituted for o2
> >> |then S is a subtype of T.
>
> That seems overly restrictive, because it wouldn't allow S to
> override a method of T and make it do something different --
> which we do all the time in practice.
>
> >> Class contracts must hold for subclasses.
>
> That sounds like a much better way of saying it!
>

Yeah, I would agree with that latter definition. The trouble is that
few programs - and fewer programmers - really define which parts are
contracts, so it's much easier to say "a subclass behaves just like
the superclass(es) do(es)" - but it would be more accurate to qualify
that with "in the ways that the superclass(es) define as standard
behaviour".

ChrisA
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: an oop question

2022-11-04 Thread Chris Angelico
On Sat, 5 Nov 2022 at 02:18, Greg Ewing  wrote:
>
> On 4/11/22 12:50 am, Chris Angelico wrote:
> > In Python, everything is an object. Doesn't that equally mean that
> > Python is purely OOP?
>
> Depends on what you mean by "purely oop". To me it suggests a
> language in which dynamically-dispatched methods are the only
> form of code. Python is not one of those, because it has
> stand-alone functions.
>

Define "stand-alone". In Java, all code has to be associated with a
class file, but they can be static methods. A Java-like language in
which classes are themselves first-class objects (and thus static
methods are instance methods on the class) would, in a sense, have
nothing but dynamically-dispatched methods as the only form of code.
It wouldn't be materially different from regular Java though (at
least, not for the sake of this purity; having first-class classes
would probably have other benefits).

Pike code, like Java code, is always associated with an object or a
program (Pike's name for a class). However, built-in functions
(implemented in C) can stand entirely alone. Would Pike become "purely
OOP" if all standalone builtins were deemed to be methods of some
global object? It wouldn't materially change anything.

Maybe it's one of those terms that is useless for actual coding
(because practicality beats purity), but good for discussions?

Good for arguments, at least.

ChrisA
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Operator: inappropriate wording?

2022-11-04 Thread Chris Angelico
On Thu, 3 Nov 2022 at 10:17, elas tica  wrote:
>
> Le lundi 31 octobre 2022 à 22:18:57 UTC+1, Chris Angelico a ecrit :
> > Wording is hard. Just ask the SQL standard whether NULL is a value.
> >
>
> Indeed, but I think our problem here is simpler ;)
>
> One could for example omit the incorrect term "operator" while remaining 
> unambiguous. This would give:

Yep. The word "operator" is incorrect when referring to Python's comma
(in contrast to, say, C, where the comma actually *is* an operator);
and from my understanding, the docs have already been updated to fix
this.

ChrisA
-- 
https://mail.python.org/mailman/listinfo/python-list


ANN: pdfposter 0.8.1 - scale and tile PDF pages to print on multiple sheets

2022-11-04 Thread Hartmut Goebel

I'm pleased to announce pdftools.pdfposter 0.8.1, a tool to scale and
tile PDF images/pages to print on multiple pages.

:Homepage:  https://pdfposter.readthedocs.io/
:Author:    Hartmut Goebel 
:License:   GNU Public License v3 or later (GPL-3.0-or-later)

:Quick Installation:
    pip install -U pdftools.pdfposter

:Tarballs:  https://pypi.org/project/pdftools.pdfposter/#files


What is pdfposter?


Scale and tile PDF images/pages to print on multiple pages.

``Pdfposter`` can be used to create a large poster by building it from
multiple pages and/or printing it on large media. It expects as input a
PDF file, normally printing on a single page. The output is again a
PDF file, maybe containing multiple pages together building the
poster.
The input page will be scaled to obtain the desired size.

This is much like ``poster`` does for Postscript files, but working
with PDF. Since sometimes poster does not like your files converted
from PDF. :-) Indeed ``pdfposter`` was inspired by ``poster``.

For more information please refer to the manpage or visit
the `project homepage `_.


What's new in version 0.8.1
-

* This is a bug-fix release for release 0.8.

What's new in version 0.8
-

* Be less strict when reading PDF files.

* Enhance some help messages.

* Drop support for Python 2 and Python <= 3.5. Minimum supported 
versions are

  now 3.6 to 3.10.

* Internal changes:

  - Update required version of `PyPDF` to 2.1.1.
  - Enhance code quality.

--
Regards
Hartmut Goebel

| Hartmut Goebel  | [email protected]   |
| www.crazy-compilers.com | compilers which you thought are impossible |

--
https://mail.python.org/mailman/listinfo/python-list


Re: typing: property/setter and lists? [RESOLVED ERRATA]

2022-11-04 Thread Paulo da Silva

Às 07:52 de 04/11/22, dn escreveu:

On 04/11/2022 07.50, Chris Angelico wrote:

On Fri, 4 Nov 2022 at 05:48, Paulo da Silva
 wrote:


Às 05:32 de 03/11/22, Paulo da Silva escreveu:

Às 03:24 de 03/11/22, Paulo da Silva escreveu:

Hi!

And a typing problem again!!!
___
class C:
  def __init__(self):
  self.__foos=5*[0]

  @property
  def foos(self) -> list[int]:
  return self.__foos

  @foos.setter
  def foos(self,v: int):
  self.__foos=[v for __i in self.__foos]

c=C()
c.foos=5
print(c.foos)
___

mypy gives the following error:
error: Incompatible types in assignment (expression has type "int",
variable has type "List[int]")

How do I turn around this?


Changing def foos(self) -> list[int]:  to
   def foos(self) -> Union[list[int]]:

I meant, of course,
def foos(self) -> Union[list[int],int]:



Ohhh! I thought this was triggering a strange quirk of the checker in
some way...



Yes, these personal styles (?quirks) are off-putting to others.

Plus "_" means (more or less) "not used anymore"
and for most of us, a weak-identifier name such as "i" is indeed "an 
indexer/counter/... "

Thank you for the suggestions.
BTW, I am not a python pro programmer. I use it as a tool as many other 
tools and some other (few) languages.


..

...and whilst I'm griping,
"To help us to help you please copy-paste the *exact* message"
has been followed by:
"I'm sorry. A bad transposition of the text."

copy-paste for the win!
(and to keep others happy to spend their voluntary time helping you - 
more working-with-the-team thinking to consider - please)
The full original message was there. Seemed to me that that was obvious 
considering the simplicity of the subject and the illustrative toy example.

Anyway, I'm sorry.

Thank you.
Paulo


--
https://mail.python.org/mailman/listinfo/python-list


Re: Operator: inappropriate wording?

2022-11-04 Thread elas tica
Le vendredi 4 novembre 2022 à 16:29:34 UTC+1, Chris Angelico a écrit :

> Yep. The word "operator" is incorrect when referring to Python's comma 
> (in contrast to, say, C, where the comma actually *is* an operator); 
> and from my understanding, the docs have already been updated to fix 
> this. 
> 
> ChrisA

Thanks Chris for your response. 

This problem of an imaginary comma operator was quite clear. The issue I opened 
is more about the so-called = operator which is not considered as such by the 
official Python FAQ, at the same place where it was said that comma was not an 
operator either.

By the way, I opened another issue because the dot operator is missing in the 
list of tokens that are operators and R. Hettinger seems to consider my 
objection as admissible. The issue is here: 
https://github.com/python/cpython/issues/99000

It seems that there are some problems with the use of the term operator in the 
official documentation ;)
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: ANN: pdfposter 0.8.1 - scale and tile PDF pages to print on multiple sheets

2022-11-04 Thread jkn
On Friday, November 4, 2022 at 6:21:55 PM UTC, Hartmut Goebel wrote:
> I'm pleased to announce pdftools.pdfposter 0.8.1, a tool to scale and 
> tile PDF images/pages to print on multiple pages. 
> 
> :Homepage:  https://pdfposter.readthedocs.io/ 
> :Author:Hartmut Goebel  
> :License:   GNU Public License v3 or later (GPL-3.0-or-later) 
> 
> :Quick Installation: 
> pip install -U pdftools.pdfposter 
> 
> :Tarballs:  https://pypi.org/project/pdftools.pdfposter/#files 
> 
> 
> What is pdfposter? 
>  
> 
> Scale and tile PDF images/pages to print on multiple pages. 
> 
> ``Pdfposter`` can be used to create a large poster by building it from 
> multiple pages and/or printing it on large media. It expects as input a 
> PDF file, normally printing on a single page. The output is again a 
> PDF file, maybe containing multiple pages together building the 
> poster. 
> The input page will be scaled to obtain the desired size. 
> 
> This is much like ``poster`` does for Postscript files, but working 
> with PDF. Since sometimes poster does not like your files converted 
> from PDF. :-) Indeed ``pdfposter`` was inspired by ``poster``. 
> 
> For more information please refer to the manpage or visit 
> the `project homepage `_. 
> 
> 
> What's new in version 0.8.1 
> - 
> 
> * This is a bug-fix release for release 0.8. 
> 
> What's new in version 0.8 
> - 
> 
> * Be less strict when reading PDF files. 
> 
> * Enhance some help messages. 
> 
> * Drop support for Python 2 and Python <= 3.5. Minimum supported 
> versions are 
>   now 3.6 to 3.10. 
> 
> * Internal changes: 
> 
>   - Update required version of `PyPDF` to 2.1.1. 
>   - Enhance code quality. 
> 
> -- 
> Regards 
> Hartmut Goebel 
> 
> | Hartmut Goebel | [email protected] | 
> | www.crazy-compilers.com | compilers which you thought are impossible |

Thanks for this - yes, I remember poster for n-up Postscript files...

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: an oop question

2022-11-04 Thread Greg Ewing

On 5/11/22 4:25 am, Chris Angelico wrote:

Maybe it's one of those terms that is useless for actual coding
(because practicality beats purity), but good for discussions?


I'm not sure it's much good for discussions, either. I don't
really care whether a language is "purely OO" or not, whatever
that means, because I don't see purity of OO as a virtue.
All I care about is what actual features then language has.

--
Greg
--
https://mail.python.org/mailman/listinfo/python-list


Re: an oop question

2022-11-04 Thread Julieta Shem
Greg Ewing  writes:

> On 4/11/22 1:29 am, Julieta Shem wrote:
>> Perhaps I can reduce the
>> class Pair to just being a pair as we know it, made of two things, then
>> we create a class called Sequence, which is really a composition of
>> Pairs, comes with a length method and we derive Stack from it.
>
> That sounds better. But be careful -- a Sequence class would
> probably be expected to have methods for e.g. inserting and
> removing things in the middle, which you might not want to
> allow for a Stack.

I guess we could override those and raise NotImplementedError?

I don't actually know how to do that.  Say I have those two classes
Empty and Pair.  Here's a way to design Seq:

class Seq:
  class SeqEmpty(Empty):
pass
  class SeqPair(Pair):
def insert(self):
  return ...
def remove(self):
  return ...
  def __new__(clss, *args):
if len(args) == 0:
  return Seq.SeqEmpty()
else:
  return Seq.SeqPair(*args)

How do I override insert in Stack?

class Stack(Seq):
  def insert(self):
raise NotImplementedError
   
That doesn't work because when I create an object of type Stack, it is
actually an object of type Seq.SeqEmpty or of type Seq.SeqPair.  So it
seems that Stack should inherit Seq.SeqPair or Seq.SeqEmpty and these
unions begin to look like a lot of typing.
-- 
https://mail.python.org/mailman/listinfo/python-list