Re: how to discover what values produced an exception?

Liste des GroupesRevenir à cl python 
Sujet : Re: how to discover what values produced an exception?
De : 2QdxY4RzWzUUiLuE (at) *nospam* potatochowder.com
Groupes : comp.lang.python
Date : 04. May 2024, 21:33:00
Autres entêtes
Message-ID : <mailman.6.1714852629.3326.python-list@python.org>
References : 1 2
On 2024-05-03 at 10:56:39 -0300,
Johanne Fairchild via Python-list <python-list@python.org> wrote:

How to discover what values produced an exception?  Or perhaps---why
doesn't the Python traceback show the values involved in the TypeError?
For instance:
 
--8<-------------------------------------------------------->8---
(0,0) < 4
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: '<' not supported between instances of 'tuple' and 'int'
--8<-------------------------------------------------------->8---
 
It could have said something like:
 
--8<-------------------------------------------------------->8---
TypeError: '<' not supported between instances of 'tuple' and 'int'
  in (0,0) < 4.
--8<-------------------------------------------------------->8---
 
We would know which were the values that caused the problem, which would
be very helpful.

I'm not disagreeing that knowing the values could be useful in many
cases.  In the general case, though, it's not practical.  Consider a
function like this:

    def f(x, y):
        return g(x) < h(y)

The printed values of x, y, g(x), and h(y) could all be millions of (or
more) glyphs.  Worse, one or more of those values could contain circular
lists or similar structures.  And h or g could have changed x or y.  In
summary, printing run-time values isn't always safe or useful.  At least
printing the types is safe.  In the face of ambiguity, refuse to guess.

Date Sujet#  Auteur
3 May 24 * how to discover what values produced an exception?12Johanne Fairchild
3 May 24 +* Re: how to discover what values produced an exception?4Stefan Ram
4 May 24 i`* Re: how to discover what values produced an exception?3Stefan Ram
4 May 24 i +- Re: how to discover what values produced an exception?1Stefan Ram
4 May 24 i `- Re: how to discover what values produced an exception?1Stefan Ram
3 May 24 +* Re: how to discover what values produced an exception?3Thomas Passin
4 May 24 i`* Re: how to discover what values produced an exception?2Alan Bawden
6 May 24 i `- Re: how to discover what values produced an exception?1Chris Angelico
4 May 24 +- Re: how to discover what values produced an exception?1dieter.maurer
4 May 24 +- Re: how to discover what values produced an exception?12QdxY4RzWzUUiLuE
4 May 24 +- Re: how to discover what values produced an exception?1Stefan Ram
3 May 24 `- Re: how to discover what values produced an exception?1Left Right

Haut de la page

Les messages affichés proviennent d'usenet.

NewsPortal