Re: sre_constants MODIFIED CLASS - ERROR

2022-06-25 Thread נתי שטרן
correction:
This is CPYTHON * and not * CYTHON

https://github.com/python/cpython/blob/3.10/Lib/sre_constants.py

‫בתאריך שבת, 25 ביוני 2022 ב-3:27 מאת ‪Dennis Lee Bieber‬‏ <‪
wlfr...@ix.netcom.com‬‏>:‬

> On Fri, 24 Jun 2022 18:27:33 +0300, ???   declaimed
> the following:
>
> >I copied  most of the libraries from cython
>
> I doubt that... cython is a specialized Python COMPILER system.
> "CPython" is the common interpreted Python language (implemented in C), and
> is the most likely source of the packages you are mongrelizing..
>
> https://cython.org/
> """
> Cython is an optimising static compiler for both the Python programming
> language and the extended Cython programming language (based on Pyrex). It
> makes writing C extensions for Python as easy as Python itself.
> """
> """
> The Cython language is a superset of the Python language that additionally
> supports calling C functions and declaring C types on variables and class
> attributes. This allows the compiler to generate very efficient C code from
> Cython code. The C code is generated once and then compiles with all major
> C/C++ compilers in CPython 2.6, 2.7 (2.4+ with Cython 0.20.x) as well as
> 3.3 and all later versions.
> """
>
>
> --
> Wulfraed Dennis Lee Bieber AF6VN
> wlfr...@ix.netcom.com
> http://wlfraed.microdiversity.freeddns.org/
> --
> https://mail.python.org/mailman/listinfo/python-list
>


-- 

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


Re: sre_constants MODIFIED CLASS - ERROR

2022-06-24 Thread Dennis Lee Bieber
On Fri, 24 Jun 2022 18:27:33 +0300, ???   declaimed
the following:

>I copied  most of the libraries from cython

I doubt that... cython is a specialized Python COMPILER system.
"CPython" is the common interpreted Python language (implemented in C), and
is the most likely source of the packages you are mongrelizing..

https://cython.org/
"""
Cython is an optimising static compiler for both the Python programming
language and the extended Cython programming language (based on Pyrex). It
makes writing C extensions for Python as easy as Python itself. 
"""
"""
The Cython language is a superset of the Python language that additionally
supports calling C functions and declaring C types on variables and class
attributes. This allows the compiler to generate very efficient C code from
Cython code. The C code is generated once and then compiles with all major
C/C++ compilers in CPython 2.6, 2.7 (2.4+ with Cython 0.20.x) as well as
3.3 and all later versions.
"""


-- 
Wulfraed Dennis Lee Bieber AF6VN
wlfr...@ix.netcom.comhttp://wlfraed.microdiversity.freeddns.org/
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: sre_constants MODIFIED CLASS - ERROR

2022-06-24 Thread Dennis Lee Bieber
On Fri, 24 Jun 2022 15:14:50 +0300, ???   declaimed
the following:

>My TARGET  is to bind many code libraries to one Huge code file that works
>optimally and do optimizations if needed.
>In this file have code of huge part of falconpy, ALL code of re, argparse,
>are and many other code libraries
>
>This code file is contained 10k lines of python code
>

Which means any program that just uses regular expressions has to
import, parse, and byte-code compile all 10K lines.

There is a reason Python doesn't make super all-in-one libraries.


-- 
Wulfraed Dennis Lee Bieber AF6VN
wlfr...@ix.netcom.comhttp://wlfraed.microdiversity.freeddns.org/
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: sre_constants MODIFIED CLASS - ERROR

2022-06-24 Thread נתי שטרן
I copied  most of the libraries from cython
בתאריך יום ו׳, 24 ביוני 2022, 17:18, מאת Roel Schroeven ‏<
r...@roelschroeven.net>:

> Op 24/06/2022 om 14:14 schreef נתי שטרן:
> > My TARGET  is to bind many code libraries to one Huge code file that
> > works optimally and do optimizations if needed.
> > In this file have code of huge part of falconpy, ALL code of re,
> > argparse, are and many other code libraries
> Don't do that. Sorry, it's just as simple as that. Don't do that. All
> those modules are not designed to put together like that, all their
> namespaces merged together. Don't do it.
> Even if you could eventually get it to work, it would not be any more
> optimal.
>
> If you need more performance, look into things like Pypy or Cython.
>
> --
> "Experience is that marvelous thing that enables you to recognize a
> mistake when you make it again."
>  -- Franklin P. Jones
>
>
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: sre_constants MODIFIED CLASS - ERROR

2022-06-24 Thread Roel Schroeven

Op 24/06/2022 om 14:14 schreef נתי שטרן:
My TARGET  is to bind many code libraries to one Huge code file that 
works optimally and do optimizations if needed.
In this file have code of huge part of falconpy, ALL code of re, 
argparse, are and many other code libraries
Don't do that. Sorry, it's just as simple as that. Don't do that. All 
those modules are not designed to put together like that, all their 
namespaces merged together. Don't do it.
Even if you could eventually get it to work, it would not be any more 
optimal.


If you need more performance, look into things like Pypy or Cython.

--
"Experience is that marvelous thing that enables you to recognize a
mistake when you make it again."
-- Franklin P. Jones

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


Re: sre_constants MODIFIED CLASS - ERROR

2022-06-24 Thread נתי שטרן
Where found the license of those libraries?
P. S.  The copied and modified code used only for internal use


בתאריך יום ו׳, 24 ביוני 2022, 15:28, מאת Chris Angelico ‏:

> ‪On Fri, 24 Jun 2022 at 22:16, ‫נתי שטרן‬‎  wrote:‬
> >
> > My TARGET  is to bind many code libraries to one Huge code file that
> works
> > optimally and do optimizations if needed.
> > In this file have code of huge part of falconpy, ALL code of re,
> argparse,
> > are and many other code libraries
> >
> > This code file is contained 10k lines of python code
> >
>
> Did you check the license terms of all of those libraries? Are you
> even legally allowed to do that?
>
> ChrisA
> --
> https://mail.python.org/mailman/listinfo/python-list
>
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: sre_constants MODIFIED CLASS - ERROR

2022-06-24 Thread Chris Angelico
‪On Fri, 24 Jun 2022 at 22:16, ‫נתי שטרן‬‎  wrote:‬
>
> My TARGET  is to bind many code libraries to one Huge code file that works
> optimally and do optimizations if needed.
> In this file have code of huge part of falconpy, ALL code of re, argparse,
> are and many other code libraries
>
> This code file is contained 10k lines of python code
>

Did you check the license terms of all of those libraries? Are you
even legally allowed to do that?

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


Re: sre_constants MODIFIED CLASS - ERROR

2022-06-24 Thread נתי שטרן
My TARGET  is to bind many code libraries to one Huge code file that works
optimally and do optimizations if needed.
In this file have code of huge part of falconpy, ALL code of re, argparse,
are and many other code libraries

This code file is contained 10k lines of python code



בתאריך יום ו׳, 24 ביוני 2022, 14:37, מאת Roel Schroeven ‏<
r...@roelschroeven.net>:

> Op 24/06/2022 om 11:10 schreef נתי שטרן:
> > OK. I lifted the full library to a HUGE python file that was saved on LAN
> > in MY WORK
> > Do I need to lift many other  libraries to the file?
> > I glad to any answer
> Answer this: what is it that your _actually_ trying to do? What is the
> ultimate goal of all that copying and changing? Cause there is almost
> always a better and easier way.
>
> --
> "You can fool some of the people all the time, and all of the people some
> of the time, but you cannot fool all of the people all of the time."
>  -- Abraham Lincoln
> "You can fool too many of the people too much of the time."
>  -- James Thurber
>
> --
> https://mail.python.org/mailman/listinfo/python-list
>
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: sre_constants MODIFIED CLASS - ERROR

2022-06-24 Thread Roel Schroeven

Op 24/06/2022 om 11:10 schreef נתי שטרן:

OK. I lifted the full library to a HUGE python file that was saved on LAN
in MY WORK
Do I need to lift many other  libraries to the file?
I glad to any answer
Answer this: what is it that your _actually_ trying to do? What is the 
ultimate goal of all that copying and changing? Cause there is almost 
always a better and easier way.


--
"You can fool some of the people all the time, and all of the people some
of the time, but you cannot fool all of the people all of the time."
-- Abraham Lincoln
"You can fool too many of the people too much of the time."
-- James Thurber

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


Re: sre_constants MODIFIED CLASS - ERROR

2022-06-24 Thread נתי שטרן
OK. I lifted the full library to a HUGE python file that was saved on LAN
in MY WORK
Do I need to lift many other  libraries to the file?
I glad to any answer
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: sre_constants MODIFIED CLASS - ERROR

2022-06-24 Thread Roel Schroeven

Op 24/06/2022 om 10:43 schreef נתי שטרן:

what's the problem with the code
Have you seen the replies from Mats Wichmann and Chris Angelico, who 
helpfully pointed out some problems with your code and possible 
improvements? Please take those into account instead of asking the same 
thing over and over.


--
"Il semble que la perfection soit atteinte non quand il n'y a plus rien à
ajouter, mais quand il n'y a plus rien à retrancher."
"Perfectie is niet bereikt als er niets meer toe te voegen is, maar als er
niets meer weg te nemen is."
-- Antoine de Saint-Exupéry

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


Re: sre_constants MODIFIED CLASS - ERROR

2022-06-24 Thread נתי שטרן
I did the changes on local copy of this code

‫בתאריך יום ו׳, 24 ביוני 2022 ב-11:50 מאת ‪Chris Angelico‬‏ <‪
ros...@gmail.com‬‏>:‬

> ‪On Fri, 24 Jun 2022 at 18:43, ‫נתי שטרן‬‎  wrote:‬
> >
> > class _NamedIntConstant(int):
> > def __new__(cls, value, name):
> > self = super(_NamedIntConstant, cls).__new__(cls, value)
> > self.name = name
> > return self
> >
> > def __repr__(self):
> > return self.name
> >
> > __reduce__ = None
> >  MAXREPEAT = _NamedIntConstant(32,name=str(32))
> >
> > what's the problem with the code
>
> You ripped a bunch of code from the standard library without
> understanding what it does, and now it doesn't work. The problem is
> more with your methodology than your code.
>
> Why are you doing this? Why not simply use what's there?
>
> If you REALLY need to make source-level changes, make *changes*, don't
> try to lift small parts out. Also, you will need to spend some hours
> getting to know the code that you're mutating.
>
> Is there an alternative newsgroup for
> lazy-python-users-who-dont-want-to-do-the-w...@groups.google.com ?
>
> ChrisA
> --
> https://mail.python.org/mailman/listinfo/python-list
>


-- 

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


Re: sre_constants MODIFIED CLASS - ERROR

2022-06-24 Thread Chris Angelico
‪On Fri, 24 Jun 2022 at 18:43, ‫נתי שטרן‬‎  wrote:‬
>
> class _NamedIntConstant(int):
> def __new__(cls, value, name):
> self = super(_NamedIntConstant, cls).__new__(cls, value)
> self.name = name
> return self
>
> def __repr__(self):
> return self.name
>
> __reduce__ = None
>  MAXREPEAT = _NamedIntConstant(32,name=str(32))
>
> what's the problem with the code

You ripped a bunch of code from the standard library without
understanding what it does, and now it doesn't work. The problem is
more with your methodology than your code.

Why are you doing this? Why not simply use what's there?

If you REALLY need to make source-level changes, make *changes*, don't
try to lift small parts out. Also, you will need to spend some hours
getting to know the code that you're mutating.

Is there an alternative newsgroup for
lazy-python-users-who-dont-want-to-do-the-w...@groups.google.com ?

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


sre_constants MODIFIED CLASS - ERROR

2022-06-24 Thread נתי שטרן
class _NamedIntConstant(int):
def __new__(cls, value, name):
self = super(_NamedIntConstant, cls).__new__(cls, value)
self.name = name
return self

def __repr__(self):
return self.name

__reduce__ = None
 MAXREPEAT = _NamedIntConstant(32,name=str(32))

what's the problem with the code
-- 
https://mail.python.org/mailman/listinfo/python-list


[issue34331] Incorrectly pluralized abstract class error message

2019-09-11 Thread Stéphane Wirtel

Stéphane Wirtel  added the comment:

Thank you for your contribution

--
resolution:  -> fixed
stage: patch review -> resolved
status: open -> closed
versions:  -Python 3.8

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue34331] Incorrectly pluralized abstract class error message

2019-09-11 Thread Stéphane Wirtel

Stéphane Wirtel  added the comment:


New changeset 4a12a178f4a6b9a59d97fecc727f2b6b28dfc85f by Stéphane Wirtel 
(Daniel Andrade) in branch 'master':
bpo-34331: Fix incorrectly pluralized abstract class error message. (GH-8670)
https://github.com/python/cpython/commit/4a12a178f4a6b9a59d97fecc727f2b6b28dfc85f


--
nosy: +matrixise

___
Python tracker 
<https://bugs.python.org/issue34331>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue34331] Incorrectly pluralized abstract class error message

2019-08-09 Thread Sanyam Khurana


Sanyam Khurana  added the comment:

Adding 3.9 to this bug. I've reviewed the PR and it looks good to me.

--
nosy: +CuriousLearner
versions: +Python 3.9

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue34331] Incorrectly pluralized abstract class error message

2018-08-04 Thread Daniel Andrade Groppe


Change by Daniel Andrade Groppe :


--
keywords: +patch
pull_requests: +8162
stage:  -> patch review

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue34331] Incorrectly pluralized abstract class error message

2018-08-03 Thread Eric V. Smith


Eric V. Smith  added the comment:

Actually, this one is probably easier to fix. In my opinion, #34127 is more 
important to fix, since it's seen much more often than the message about 
abstract base classes.

I wouldn't necessarily object to fixing this one, I just personally think it's 
not worth the hassle.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue34331] Incorrectly pluralized abstract class error message

2018-08-03 Thread ppperry


ppperry  added the comment:

No, this isn't causing me an actual problem, however the related issue34127 was 
accepted, and this one should be no harder to fix.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue34331] Incorrectly pluralized abstract class error message

2018-08-03 Thread Eric V. Smith


Eric V. Smith  added the comment:

I'm not sure the effort and code is justified for a trivial fix to an error 
message. Is this causing some actual problem?

--
nosy: +eric.smith
type:  -> behavior

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue34331] Incorrectly pluralized abstract class error message

2018-08-03 Thread ppperry


New submission from ppperry :

>>> class abstract(abc.ABC):
... @abc.abstractmethod
... def meth():
... pass
...
>>> x()
Traceback (most recent call last):
  File "", line 1, in 
TypeError: Can't instantiate abstract class x with abstract methods meth

Error should be "Can't instantiate abstract class abstract with abstract method 
meth" in the singular, because there is only one abstract method.

--
components: Interpreter Core, Library (Lib)
messages: 323059
nosy: Anjali Bansal, ppperry, rhettinger, serhiy.storchaka, terry.reedy, xtreak
priority: normal
severity: normal
status: open
title: Incorrectly pluralized abstract class error message
versions: Python 3.8

___
Python tracker 
<https://bugs.python.org/issue34331>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



Re: Class - error return

2016-09-06 Thread Smith
From: Smith 

On 06/09/2016 11:23, Peter Otten wrote:
> If so look at
>
>> >  ...: def __str__(self):
>> >  ...: return "Visitor: %i, Contacts: %i %
>> > (self.visits,self.contacts)"
> once more. Where are the quotes? Where should the be?
>
>
>
I solved the problem.
thank you Peter

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


Re: Class - error return

2016-09-06 Thread nospam . Smith
On 06/09/2016 11:23, Peter Otten wrote:
> If so look at
>
>> >  ...: def __str__(self):
>> >  ...: return "Visitor: %i, Contacts: %i %
>> > (self.visits,self.contacts)"
> once more. Where are the quotes? Where should the be?
>
>
>
I solved the problem.
thank you Peter

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


Re: Class - error return

2016-09-06 Thread Smith

On 06/09/2016 11:23, Peter Otten wrote:

If so look at


>  ...: def __str__(self):
>  ...: return "Visitor: %i, Contacts: %i %
> (self.visits,self.contacts)"

once more. Where are the quotes? Where should the be?




I solved the problem.
thank you Peter
--
https://mail.python.org/mailman/listinfo/python-list


Re: Class - error return

2016-09-06 Thread Peter Otten
Smith wrote:

> you can help me ?

Yes ;) But you might consider posting on python-tutor instead of python-
list.

> I can not understand where is the error in this script.

It's always a good idea to state both what you expect and what you get 
instead explicitly, in plain english.

> In [72]: day1 = Day(8,9)

> In [74]: print(day1)
> Visitor: %i, Contacts: %i % (self.visits,self.contacts)

That might pass as the "what you get" part; I suppose you expect it to print

Visitor: 8, Contacts: 9

If so look at

>  ...: def __str__(self):
>  ...: return "Visitor: %i, Contacts: %i %
> (self.visits,self.contacts)"

once more. Where are the quotes? Where should the be?



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


Class - error return

2016-09-06 Thread Smith

Hi,
you can help me ?
I can not understand where is the error in this script.
Use Python3.


In [71]: class Day(object):
...: def __init__(self,visits,contacts):
...: self.visits = visits
...: self.contacts = contacts
...: def __add__(self,other):
...: total_visits = self.visits + other.visits
...: total_contacts = self.contacts + other.contacts
...: return Day(total_visits,total_contacts)
...: def __radd__(self,other):
...: if other == 0:
...: return self
...: else:
...: return self.__add__(other)
...: def __str__(self):
...: return "Visitor: %i, Contacts: %i % 
(self.visits,self.contacts)"

...:
...:



In [72]: day1 = Day(8,9)

In [73]: day2 = Day(7,7)

In [74]: print(day1)
Visitor: %i, Contacts: %i % (self.visits,self.contacts)

In [75]: print(day2)
Visitor: %i, Contacts: %i % (self.visits,self.contacts)
--
https://mail.python.org/mailman/listinfo/python-list


[issue21227] Decimal class error messages for integer division aren't good

2014-10-14 Thread Stefan Krah

Stefan Krah added the comment:

I guess there's not much to be done here.

--
resolution:  - wont fix
stage:  - resolved
status: open - closed

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue21227
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue21227] Decimal class error messages for integer division aren't good

2014-04-16 Thread Stefan Krah

Stefan Krah added the comment:

It is hard to get fine grained error messages in _decimal, since
the errors come from libmpdec.  A clean solution would require
changes to libmpdec, and I'm reluctant to do that right now.

It is certainly possible to document DivisionImpossible etc.

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue21227
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue21227] Decimal class error messages for integer division aren't good

2014-04-16 Thread Stefan Krah

Stefan Krah added the comment:

Meanwhile, the pure Python decimal versions prior to Python 3.2
have better error messages.

Right now in Python 3.3+ it is hard to import the Python version
without going into contortions, but that may be fixed in #19232.

--
dependencies: +Speed up _decimal import

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue21227
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue21227] Decimal class error messages for integer division aren't good

2014-04-16 Thread leewz

leewz added the comment:

Fine grained? Do you mean that the error can't be distinguished from other such 
errors? Or that it's difficult to attach the message to DivisionError? I 
thought DivisionError was always about precision.

I looked up the error in libmpdec:
This occurs and signals invalid-operation if the integer result of a 
divide-integer or remainder operation had too many digits (would be longer than 
precision). The result is [0,qNaN]. 
(http://speleotrove.com/decimal/daexcep.html)

Now I'm more confused. Though it mentions precision, it is talking about the 
*result's* precision being too large (something which shouldn't happen with 
Python's unbounded ints, right?), rather than being unable to give a sane 
answer due to not having *enough* digits. That's also what the 2.7 error is:
decimal.InvalidOperation: quotient too large in //, % or divmod

I'm very much content with documenting it, but if possible, I'd like to 
understand whether this is an issue to take up with libmpdec.

P.S.: As a side-note to others, Python floats allows float%int even when 
precision isn't high enough, and seems to always returns 0.0 with no warning. 
So behavior is inconsistent, if that's important to anyone here.

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue21227
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue21227] Decimal class error messages for integer division aren't good

2014-04-16 Thread Stefan Krah

Stefan Krah added the comment:

My apologies if that wasn't clear: fine grained refers to the exception
messages.  A function can raise InvalidOperation for different reasons.

decimal.py gives a specific error message in each case. libmpdec just
signals the standard conforming InvalidOperation.

The relevant passage from the standard is here:

http://speleotrove.com/decimal/daops.html#refremain

  This operation will fail under the same conditions as integer division.

decimal.py, decNumber and libmpdec all do the same thing, so there is no
libmpdec issue other than that the error *messages* could be improved.

I fully understand if you find the behavior surprising (after all the remainder
fits in the precision), but as long as we follow the standard we can't change
that.

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue21227
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue21227] Decimal class error messages for integer division aren't good

2014-04-16 Thread leewz

leewz added the comment:

Nah. I found it surprising at first, but like I said, it's like the computer is 
given the first 28 digits of a number and then asked to figure out the 30th 
digit.

What I'm confused about is how it fits the definition of division impossible 
given by libmpdec's docs (about the result size), and whether you're saying 
it's difficult to translate the `[class 'decimal.DivisionImpossible']` part 
to an error message.

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue21227
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue21227] Decimal class error messages for integer division aren't good

2014-04-16 Thread Stefan Krah

Stefan Krah added the comment:

In the case of DivisionImpossible it would actually be possible to use
the error message 'quotient too large in //, % or divmod'.

But that's just one condition.  In the case of InvalidOperation there
are something like 30 different error messages.

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue21227
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue21227] Decimal class error messages for integer division aren't good

2014-04-16 Thread Raymond Hettinger

Raymond Hettinger added the comment:

 It is certainly possible to document DivisionImpossible etc.

This should not be done.  We've made strong efforts to not extend the Decimal 
Arithmetic Specification.

Also, the API already suffers from high complexity.  Adding more exceptions to 
the mix just makes the module harder to learn.

Instead, you are welcome to add more specific text messages to the existing 
(and standards compliant) exceptions:

   raise InvalidOperation(Not enough precision to compute the answer.)

 I found it surprising at first, but like I said, it's like 
 the computer is given the first 28 digits of a number and 
 then asked to figure out the 30th digit.

People are always surprised when their mental model conflicts with the actual 
design model.  That doesn't mean the implementation should change.

There may be a documentation issue, but then again, people who are surprised 
usually haven't studied the docs in detail.

My overall sense for this bug report is that there isn't a real problem that 
needs to be solved.  AFAICT, this particular confusion has never arisen 
before (i.e. bug reports, questions in python classes, posts on stackoverlow, 
blog posts, etc).  Likewise, the issue does not seem to have ever arisen in the 
many other non-Python implementations of the decimal spec.

I recommend that this either be closed or be limited to tweaking some of the 
error messages for existing exceptions.

--
nosy: +facundobatista, rhettinger, tim.peters
priority: normal - low
versions: +Python 3.5 -Python 3.3, Python 3.4

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue21227
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue21227] Decimal class error messages for integer division aren't good

2014-04-16 Thread Stefan Krah

Stefan Krah added the comment:

Raymond Hettinger rep...@bugs.python.org wrote:
  It is certainly possible to document DivisionImpossible etc.
 
 This should not be done.  We've made strong efforts to not extend the Decimal 
 Arithmetic Specification.

The exceptions are already there:

Python 2.7.3 (default, Mar 13 2014, 11:03:55)
[GCC 4.7.2] on linux2
Type help, copyright, credits or license for more information.
 import decimal
 print(decimal.DivisionImpossible.__doc__)
Cannot perform the division adequately.

This occurs and signals invalid-operation if the integer result of a
divide-integer or remainder operation had too many digits (would be
longer than precision).  The result is [0,qNaN].

The specification distinguishes between conditions and signals. It is
true that the conditions are not technically raised, but they are very
much subclasses of InvalidOperation.

Cowlishaw himself makes the distinction between InvalidOperation
and IEEEInvalidOperation. The latter groups all conditions together:

#define DEC_IEEE_754_Invalid_operation (DEC_Conversion_syntax | \
DEC_Division_impossible |   \
DEC_Division_undefined |\
DEC_Insufficient_storage |  \
DEC_Invalid_context |   \
DEC_Invalid_operation)

So while I don't particularly care whether we document the conditions or
not, I don't think doing so would extend the specification.

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue21227
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue21227] Decimal class error messages for integer division aren't good

2014-04-16 Thread Mark Dickinson

Changes by Mark Dickinson dicki...@gmail.com:


--
nosy: +mark.dickinson

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue21227
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue21227] Decimal class error messages for integer division aren't good

2014-04-16 Thread leewz

leewz added the comment:

Total list of issues now:
- Error message for `DivisionImpossible` is
  [class 'decimal.DivisionImpossible']
  instead of an actual error message.
- `decimal.DivisionImpossible.__doc__` is empty.
- Calling `help(decimal.DivisionImpossible)` turns up nothing useful.

I checked all of these just now on my 3.2.3 (Windows). These issues are a 
CHANGE from 3.2 to 3.3. For example:
- Old error:
  decimal.InvalidOperation: quotient too large in //, % or divmod
- New error:
  InvalidOperation: [class 'decimal.DivisionImpossible']

I assume that the issues also apply to the other InvalidOperation types. So I 
guess what I'm really asking for is to pull forward the 3.2 docs and messages.

 That doesn't mean the implementation should change.

Er, I was explaining why it wasn't really surprising once I thought about it.

 There may be a documentation issue, but then again, people who are 
 surprised usually haven't studied the docs in detail.

To clarify:
- I looked at the Decimal docs
- skimmed for references to modulo and division
- looked for `DivisionImpossible`
- Then looked on Google for 'DivisionImpossible Python'.
- Experimented with changing precision and fooling around with bigger and 
smaller numbers, and realized why the operation was logically impossible.
- Came here, posted, got a response that it was a flag raised by libmpdec.

I'm not asking for a change in behavior. I did point out that it was 
inconsistent with regular floats, in case consistency with Pyfloats was a thing 
that mattered. But I don't care about that. I only worry about anyone else who 
would use Decimal coming across the same unhelpful error.

 AFAICT, this particular confusion has never arisen before (i.e. bug 
 reports, questions in python classes, posts on stackoverlow, blog posts, 
 etc).  Likewise, the issue does not seem to have ever arisen in the many 
 other non-Python implementations of the decimal spec.

I agree it'd be (very) rare, but part of the reason why it might not appear 
online is that the issues at the top of this email are relatively new (3.3).

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue21227
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue21227] Decimal class error messages for integer division aren't good

2014-04-16 Thread Stefan Krah

Stefan Krah added the comment:

leewz rep...@bugs.python.org wrote:
 - Error message for `DivisionImpossible` is
   [class 'decimal.DivisionImpossible']
   instead of an actual error message.

No, the error message for the *signal*  that is raised (InvalidOperation) lists
the *condition* that triggered the signal (DivisionImpossible).

I followed the recommendation at:

http://speleotrove.com/decimal/daexcep.html#refexcep

It is recommended that implementations distinguish the different conditions
 listed above, and also provide additional information about exceptional
 conditions where possible (for example, the operation being attempted and
 the values of the operand or operands involved).

Distinguishing the conditions is easy, adding additional information in
all cases would require changes to libmpdec.

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue21227
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue21227] Decimal class error messages for integer division aren't good

2014-04-16 Thread Stefan Krah

Stefan Krah added the comment:

The idea behind the list as the exception message is this:  If multiple
conditions would have raised the signal they are all listed, while the
highest ranking signal is the one that is ultimately raised.

 from decimal import *
 c = getcontext()
 for v in c.traps:
... c.traps[v] = True
... 
 
 Decimal(8) ** 1000
Traceback (most recent call last):
  File stdin, line 1, in module
decimal.Overflow: [class 'decimal.Overflow', class 'decimal.Inexact', 
class 'decimal.Rounded']

Exception precedence is listed here at the bottom of the page:

http://speleotrove.com/decimal/daexcep.html

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue21227
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue21227] Decimal class error messages for integer division aren't good

2014-04-15 Thread Stefan Krah

Changes by Stefan Krah stefan-use...@bytereef.org:


--
assignee: docs@python - skrah
nosy: +skrah

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue21227
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue21227] Decimal class error messages for integer division aren't good

2014-04-14 Thread leewz

New submission from leewz:

Python's `decimal.Decimal` doesn't seem to like taking modulo or intdiv of 
large Decimals by integers (where large depends on how many digits are 
internally stored).

 from decimal import *
 getcontext().prec
28
 Decimal(10**29)%1
Traceback (most recent call last):
  File stdin, line 1, in module
decimal.InvalidOperation: [class 'decimal.DivisionImpossible']
 getcontext().prec=50
 Decimal(10**29)%1
Decimal('0')

Same for `Decimal(10**29)//1`

This is a logical problem: Alice has a 100-digit number which begins with 
1543256. What is the last digit?

But I found the error hard to understand. Searching for DivisionImpossible 
didn't turn up anything immediate (it wasn't added to the official docs?). I 
was most of the way through writing out a question to StackOverflow when it 
clicked. (Also, why is it an InvalidOperation that holds an exception as a 
message? Never saw that before.)

Suggestions:
- Improve docs with further examples. The examples of InvalidOperation are 
logical MATH errors (e.g. division by 0), not logical PROGRAMMING errors.
- Uh, maybe the error message could be changed to something like, The answer 
you seek lies beyond the mantissa. Or more sanely, Not enough precision to 
compute the answer. Or something else that hints to me to look into precision.

--
assignee: docs@python
components: Documentation, Library (Lib)
messages: 216253
nosy: docs@python, leewz
priority: normal
severity: normal
status: open
title: Decimal class error messages for integer division aren't good
type: enhancement
versions: Python 3.3, Python 3.4

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue21227
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



Re: class error

2011-03-21 Thread Jean-Michel Pichavant

monkeys paw wrote:


OK, i overlooked that and the error was not very enlightening.
Thanks very much.


module.__init__() takes at most 2 arguments (3 given)

Are you sure about the clueless error message ? :)

JM



  


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


Re: class error

2011-03-20 Thread Steven D'Aprano
On Sun, 20 Mar 2011 00:08:16 +, Rhodri James wrote:

 It has to be said that the confusion is exacerbated by ignoring PEP-8
 and using the same (CamelCase) name for the module and the class. That
 does provide a rich source of errors in cases like this.

It's not so much that UserDict ignores PEP-8, as that it pre-dates PEP-8.


-- 
Steven
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: class error

2011-03-19 Thread Rhodri James

On Sat, 19 Mar 2011 02:15:55 -, Terry Reedy tjre...@udel.edu wrote:


On 3/18/2011 5:27 PM, monkeys paw wrote:

TypeError: Error when calling the metaclass bases
module.__init__() takes at most 2 arguments (3 given)

OK, i overlooked that and the error was not very enlightening.


A detailed explanation: every module is an instance of a class we will  
call Module. Every class is an instance of some class, its metaclass.  
The default metaclass, in the absence of any indication otherwise, is  
class type. So your class statement was translated to


type('FileInfo',(UserDict,), d)
where d is a dict mappint '__init__' to the function object.

type.__new__ checks the types (metaclasses) of each of the base classes.  
In particular, it sees that type(UxerDict) is Module, not type. Since it  
assumed that UserDict is a class (since you said it was), it assumed  
that Module is a proper metaclass and called

   Module('FileInfo',(UserDict,), d)
But Module is not a metaclass and does not expect the tuple of base  
classes, and Module.__new__ passed too much to Module.__init__.


Since others have made the same mistake, I opened an issue to improve  
the message.

http://bugs.python.org/issue11604


It has to be said that the confusion is exacerbated by ignoring PEP-8
and using the same (CamelCase) name for the module and the class.
That does provide a rich source of errors in cases like this.

--
Rhodri James *-* Wildebeest Herder to the Masses
--
http://mail.python.org/mailman/listinfo/python-list


class error

2011-03-18 Thread monkeys paw

I have the following file:

FileInfo.py:

import UserDict

class FileInfo(UserDict):
store file metadata
def __init__(self, filename=None):
UserDict.__init__(self)
self[name] = filename



When i import it like so:

import FileInfo


i get this error:

Traceback (most recent call last):
  File interactive input, line 1, in module
  File FileInfo.py, line 3, in module
class FileInfo(UserDict):
TypeError: Error when calling the metaclass bases
module.__init__() takes at most 2 arguments (3 given)

What is causing the error?
--
http://mail.python.org/mailman/listinfo/python-list


Re: class error

2011-03-18 Thread MRAB

On 18/03/2011 20:13, monkeys paw wrote:

I have the following file:

FileInfo.py:

import UserDict

class FileInfo(UserDict):
store file metadata
def __init__(self, filename=None):
UserDict.__init__(self)
self[name] = filename



When i import it like so:

import FileInfo


i get this error:

Traceback (most recent call last):
  File interactive input, line 1, in module
  File FileInfo.py, line 3, in module
class FileInfo(UserDict):
TypeError: Error when calling the metaclass bases
module.__init__() takes at most 2 arguments (3 given)

What is causing the error?


You're importing the module UserDict and then trying to create a
subclass of it.

The module UserDict contains the class UserDict.

You could write either:

import UserDict

class FileInfo(UserDict.UserDict):

or:

from UserDict import UserDict

class FileInfo(UserDict):
--
http://mail.python.org/mailman/listinfo/python-list


Re: class error

2011-03-18 Thread Ethan Furman

monkeys paw wrote:

I have the following file:

FileInfo.py:

import UserDict

class FileInfo(UserDict):
store file metadata
def __init__(self, filename=None):
UserDict.__init__(self)
self[name] = filename



When i import it like so:

import FileInfo


i get this error:

Traceback (most recent call last):
  File interactive input, line 1, in module
  File FileInfo.py, line 3, in module
class FileInfo(UserDict):
TypeError: Error when calling the metaclass bases
module.__init__() takes at most 2 arguments (3 given)

What is causing the error?


UserDict is a module -- you want to subclass the UserDict class inside 
the module...


class FileInfo(UserDict.UserDict):
etc etc

~Ethan~
--
http://mail.python.org/mailman/listinfo/python-list


Re: class error

2011-03-18 Thread Alexander Kapps

On 18.03.2011 21:13, monkeys paw wrote:

I have the following file:

FileInfo.py:

import UserDict


After this import statement, the name UserDict refers to the module.


class FileInfo(UserDict):


Here you are trying to subclass the module. What you need instead is:

class FileInfo(UserDict.UserDict):

Alternatively, import the UserDict class from the UserDict module 
like so:


from UserDict import UserDict

Note, that the UserDict class is obsolete, you can subclass the dict 
type directly:


class FileInfo(dict):
store file metadata
def __init__(self, filename=None):
dict.__init__(self)
self[name] = filename
--
http://mail.python.org/mailman/listinfo/python-list


Re: class error

2011-03-18 Thread monkeys paw

On 3/18/2011 4:43 PM, Alexander Kapps wrote:

On 18.03.2011 21:13, monkeys paw wrote:

I have the following file:

FileInfo.py:

import UserDict


After this import statement, the name UserDict refers to the module.


class FileInfo(UserDict):


Here you are trying to subclass the module. What you need instead is:

class FileInfo(UserDict.UserDict):


OK, i overlooked that and the error was not very enlightening.
Thanks very much.



Alternatively, import the UserDict class from the UserDict module like so:

from UserDict import UserDict

Note, that the UserDict class is obsolete, you can subclass the dict
type directly:

class FileInfo(dict):
store file metadata
def __init__(self, filename=None):
dict.__init__(self)
self[name] = filename


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


Re: class error

2011-03-18 Thread Terry Reedy

On 3/18/2011 5:27 PM, monkeys paw wrote:

TypeError: Error when calling the metaclass bases
module.__init__() takes at most 2 arguments (3 given)

OK, i overlooked that and the error was not very enlightening.


A detailed explanation: every module is an instance of a class we will 
call Module. Every class is an instance of some class, its metaclass. 
The default metaclass, in the absence of any indication otherwise, is 
class type. So your class statement was translated to


type('FileInfo',(UserDict,), d)
where d is a dict mappint '__init__' to the function object.

type.__new__ checks the types (metaclasses) of each of the base classes. 
In particular, it sees that type(UxerDict) is Module, not type. Since it 
assumed that UserDict is a class (since you said it was), it assumed 
that Module is a proper metaclass and called

  Module('FileInfo',(UserDict,), d)
But Module is not a metaclass and does not expect the tuple of base 
classes, and Module.__new__ passed too much to Module.__init__.


Since others have made the same mistake, I opened an issue to improve 
the message.

http://bugs.python.org/issue11604

--
Terry Jan Reedy

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


Mixin class error

2006-03-06 Thread Ed Leafe
In Dabo, we create cursor classes that combine the backend-specific  
dbapi cursor class with our own mixin class that adds framework- 
specific behaviors. This has been working well for a couple of years  
now with many different backends, but today I'm getting errors with  
our Firebird class. I've checked the kinterbasdb site, and found  
nothing there that was helpful. The error reads:

TypeError: Error when calling the metaclass bases
 type 'kinterbasdb.Cursor' is not an acceptable base type

Here's some simple code that will generate the error:

import kinterbasdb
KCursor = kinterbasdb.Cursor

class TestMixin(object): pass
# This next line will raise the error.
class CombinedCursor(TestMixin, KCursor): pass
myCursor = CombinedCursor()

I'm not sure exactly what this error message means, so I don't know  
how to go about fixing it. Here's my setup:

Windows 2000
Python v. 2.4.1
kinterbasdb 3.2.0a1

-- Ed Leafe
-- http://leafe.com
-- http://dabodev.com



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


Re: Mixin class error

2006-03-06 Thread Kent Johnson
Ed Leafe wrote:
 In Dabo, we create cursor classes that combine the backend-specific  
 dbapi cursor class with our own mixin class that adds framework- 
 specific behaviors. This has been working well for a couple of years  
 now with many different backends, but today I'm getting errors with  our 
 Firebird class. I've checked the kinterbasdb site, and found  nothing 
 there that was helpful. The error reads:
 
 TypeError: Error when calling the metaclass bases
 type 'kinterbasdb.Cursor' is not an acceptable base type
 
 Here's some simple code that will generate the error:
 
 import kinterbasdb
 KCursor = kinterbasdb.Cursor
 
 class TestMixin(object): pass
 # This next line will raise the error.
 class CombinedCursor(TestMixin, KCursor): pass
 myCursor = CombinedCursor()
 
 I'm not sure exactly what this error message means, so I don't know  
 how to go about fixing it.

I have no clue but googling 'type is not an acceptable base type' finds 
this thread
http://groups.google.com/group/comp.lang.python/browse_thread/thread/628b8ad34a36db17/579f716b143f4967%23579f716b143f4967?sa=Xoi=groupsrstart=0num=3

which points to the Py_TPFLAGS_BASETYPE. This example
http://www.python.org/doc/2.3.5/ext/node22.html

shows that flag being set to indicate that an extension class may be 
subclassed; the API docs confirm this:
http://docs.python.org/api/type-structs.html#l2h-968

So it looks like kinterbasdb.Cursor is a C extension class that may not 
be subclassed because Py_TPFLAGS_BASETYPE is not set. Whether this is by 
design or accident would be a question for the kinterbasdb developers.

One workaround might be to use delegation instead of subclassing...

Kent
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Mixin class error

2006-03-06 Thread Ed Leafe
On Mar 6, 2006, at 8:08 PM, Kent Johnson wrote:

 I have no clue but googling 'type is not an acceptable base type'  
 finds
 this thread
 http://groups.google.com/group/comp.lang.python/browse_thread/ 
 thread/628b8ad34a36db17/579f716b143f4967%23579f716b143f4967? 
 sa=Xoi=groupsrstart=0num=3

I spent about an hour Googling and never found that thread!

 So it looks like kinterbasdb.Cursor is a C extension class that may  
 not
 be subclassed because Py_TPFLAGS_BASETYPE is not set. Whether this  
 is by
 design or accident would be a question for the kinterbasdb developers.

OK, I'll ask them.

 One workaround might be to use delegation instead of subclassing...

Yeah, but that would involve a lot more work at this point. The  
mixin approach has been working quite well up until this problem.

-- Ed Leafe
-- http://leafe.com
-- http://dabodev.com



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


Re: Mixin class error

2006-03-06 Thread Kent Johnson
Ed Leafe wrote:
 On Mar 6, 2006, at 8:08 PM, Kent Johnson wrote:
 One workaround might be to use delegation instead of subclassing...
 
 Yeah, but that would involve a lot more work at this point. The  
 mixin approach has been working quite well up until this problem.

Automatic delegation is pretty simple, just define __getattr__() and 
__setattr__() to delegate to the wrapped class. For example
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/52295

Kent
-- 
http://mail.python.org/mailman/listinfo/python-list