Why not just show the out-of-range index?

F

Fredrik Lundh

BJörn Lindqvist said:
And you're not helping.

I've already explained why something like PyObject_IsIndexOutOfBounds
cannot work earlier in this thread.

</F>
 
J

John Machin

OKB (not okblacke) wrote:
[snip]
I think the same could be said of virtually all exceptions. What I
think would be ideal is that whenever an exception is raised, the
traceback tells you:

1) What the exception is
2) The names of the variables involved in the offending expression
(or their character position in the line)
3) The values of those variables

This would be especially useful in cases where you have some long
expression and you get a "cannot concatenate str and list" or whatever.
The irritating thing about this as it is is that you cannot tell which
variables in the expression are causing the problem.

I realize that in some cases the offending expression may not be a single variable,
but I am curious whether it would be possible for
something like this:

"1" + "2" + "3" + "4" + 5 + "6"

A few points:

1. You have difficulty determining the "offending expression" in that
example?

2. If I read your requirement properly, you want an error message that
includes the following information from the source:

example 1: "1" + "2" + "3" + "4" + 5 + "6"
left operand name: "1" + "2" + "3" + "4"
left operand value: "1234"
right operand name: 5
right operand value: 5

example 2 (simple variables): str1 = "a"; list1 = ["b"]; foo = str1 +
list1
left operand name: str1
left operand value: "a"
right operand name: list1
right operand value: ["b"]

example 3 (simple variables): str1 = "a"; str2 = "x"; list1 = ["b"];
foo = str1 + str2 + list1
left operand name: str1 + str2
left operand value: "ax"
right operand name: list1
right operand value: ["b"]

IMHO there would be no point in handling only "simple" cases like
example 2 -- firstly, you don't need it; there's only one possible
answer for "left operand name". Secondly, AFAICT, the same mechanism
would handle examples of arbitrary complexity.

My guesses: (a) Implementing this error reporting information in a new
compiler and interpreter would add considerably to the effort required,
and to the complexity and thus to the risk of error. (b) Retrofitting
it to an existing compiler and interpreter would be a nightmare.
Possible: yes. Cost/benefit ratio: very high.

3. The OP asked only for values; you are asking for names and values.
If you have a magic flak jacket, please let me know; I'd like to borrow
it occasionally :)

Cheers,
John
 
T

Terry Reedy

Russ said:
And you didn't like the "tone" of some of my earlier posts?

While Fredrik's reply is a bit short, as is sometimes his habit,
here are some things that appear to me to not have been thought through
enough:
1. some negative indexes are legal.
2. replacing short inline code with a function call on *every* index lookup
will slow down the interpreter a bit.
3. will the same check code work for even all built-in sequences?
4. how does index checking fit in with slice checking?

By the way, it is already understood that error messages could be better,
and I have thought about this one myself. You are not the first to notice,
and improvements occasionally get submitted (and later accepted) by people
with both the knowledge and motivation to do so. But insulting such people
is not helpful.

Terry Jan Reedy
 
?

=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=

Seems to me he called the suggestion (made without any
knowlage of the OP's abilities regarding C and Python's
internals) that he summit a patch, silly.

I aggree.

His response was well within the bounds of normal
usenet discourse.

Maybe I'm unusually picky, but I also feel insulted if
my suggestions are called silly - this is just like calling
myself silly. I rarely make silly suggestions deliberately
(and try to mark them as ironic in usenet if I do); so if
somebody puts them down as "silly", I'll feel insulted.

I personally don't think it is silly to suggest that an
IT professional becomes familiar with the implementation
of the Python interpreter. That code is well-written,
well-documented, so it should be feasible (rather than
being silly) for anybody with a programming background
and sufficient determination to familiarize with that code.

I take the same position for about any open-source software:
you *can* get into Apache, Mozilla, the Linux kernel,
and now the Java virtual machine if you want to. If you
don't, it's not because you can't, but because you don't
want to.

It would be unrealistic (but not silly) to suggest that
if the source code weren't available at all. It is *not*
silly to suggest that people should make efforts to
contribute to open source software.

Regards,
Martin
 
R

rurpy

Terry said:
While Fredrik's reply is a bit short, as is sometimes his habit,
here are some things that appear to me to not have been thought through
enough:
1. some negative indexes are legal.
2. replacing short inline code with a function call on *every* index lookup
will slow down the interpreter a bit.
3. will the same check code work for even all built-in sequences?
4. how does index checking fit in with slice checking?

By the way, it is already understood that error messages could be better,
and I have thought about this one myself. You are not the first to notice,
and improvements occasionally get submitted (and later accepted) by people
with both the knowledge and motivation to do so. But insulting such people
is not helpful.

I saw no posts where there OP insulted anybody without being
insulted first. It is ironic the Mr. Kern was the most consistent
insulter while at the same time accusing the OP of rudeness.

Your own post would have been more helpful (or at least less
devisive) had you left off that last sentence.
 
F

Fredrik Lundh

Martin said:
It would be unrealistic (but not silly) to suggest that
if the source code weren't available at all. It is *not*
silly to suggest that people should make efforts to
contribute to open source software.

you're forgetting that you're dealing with "squeaky wheel contributors"
here, not the kind of nice and helpful persons that actually make open
source work.

</F>
 
R

Robert Kern

I saw no posts where there OP insulted anybody without being
insulted first. It is ironic the Mr. Kern was the most consistent
insulter while at the same time accusing the OP of rudeness.

As I said, insult is in the ear of the listener, so I apologize if anyone
construed my comments as insults. However, facts are facts, and I stated them as
I believe them. If you can pick out the precise comments that you felt were
insulting, I will be happy to attempt clarifying them in a way that you do not
find insulting.

--
Robert Kern

"I have come to believe that the whole world is an enigma, a harmless enigma
that is made terrible by our own mad attempt to interpret it as though it had
an underlying truth."
-- Umberto Eco
 
?

=?ISO-8859-1?Q?BJ=F6rn_Lindqvist?=

I've already explained why something like PyObject_IsIndexOutOfBounds
cannot work earlier in this thread.

Maybe so, but that doesn't mean that it is not possible to make the
IndexError messages Pythons sequence objects throws better. You don't
need to change the semantics of x.
 
?

=?ISO-8859-1?Q?BJ=F6rn_Lindqvist?=

While Fredrik's reply is a bit short, as is sometimes his habit,
here are some things that appear to me to not have been thought through
enough:
1. some negative indexes are legal.

That could be fixed. Just substract len(L) from i if i < 0.
2. replacing short inline code with a function call on *every* index lookup
will slow down the interpreter a bit.

I can't notice any difference. On my machine, Python is compiled with
-O3 which probably inlines the function.
3. will the same check code work for even all built-in sequences?

Atleast for tuple, string and list, they can be downcasted to
PyVarObjects. So yes.
4. how does index checking fit in with slice checking?

When does slicing throw IndexErrors?
with both the knowledge and motivation to do so. But insulting such people
is not helpful.

Agreed. I don't think insulting people is helpful at all, but I don't
think "Russ" is the only one in this thread that should learn that.
 
R

Russ

Fredrik said:
you're forgetting that you're dealing with "squeaky wheel contributors"
here, not the kind of nice and helpful persons that actually make open
source work.

Please refrain from dishing out gratutious insults until you have a
clue what you are talking about. It just so happens that I *have* made
significant contributions to open-source software.

A few years ago, I spent several man-months of my own time developing a
free, open-source, full-featured GUI for voting:

http://russp.org/GVI.htm

GVI, The Graphical Voter Interface, is a GUI (Graphical User Interface)
for voting, suitable for use in private or public elections. Although
it could be adapted for online voting, it is currently intended only
for conventional "precinct" voting. For security reasons, GVI does not
require that the voter have access to a keyboard. It can handle
write-ins and multi-language elections, and it can automate voting
along party lines. GVI can be used for Condorcet Voting and Instant
Runoff Voting, which allow voters to rank the candidates in order of
preference. It can also be used for Approval Voting, which allows
voters to select more than one candidate.

More recently, I developed a free, open-source Python package for
dealing with physical scalars. It has an innovative feature that
preserves the efficiency of built-in numerical types with an optional
switch:

http://russp.org/scalar.htm

A Python class was designed to represent physical scalars and to
eliminate errors involving implicit physical units (e.g., confusing
angular degrees and radians). The standard arithmetic operators are
overloaded to provide syntax identical to that for built-in numeric
types. The scalar class comes with a complete implementation of the
standard metric system of units and many standard non-metric units. It
also allows the user to easily define a specialized or reduced set of
appropriate physical units for any particular application or domain.
Once an application has been developed and tested, the units can easily
be switched off, if desired, to achieve the execution efficiency of
operations on built-in numeric types (which can be two orders of
magnitude faster). The scalar class can also be used for discrete units
to enforce type checking of integer counts, thereby enhancing the
built-in dynamic type checking of Python.
 
R

rurpy

Martin said:
Maybe I'm unusually picky, but I also feel insulted if
my suggestions are called silly - this is just like calling
myself silly. I rarely make silly suggestions deliberately
(and try to mark them as ironic in usenet if I do); so if
somebody puts them down as "silly", I'll feel insulted.

I personally don't think it is silly to suggest that an
IT professional becomes familiar with the implementation
of the Python interpreter. That code is well-written,
well-documented, so it should be feasible (rather than
being silly) for anybody with a programming background
and sufficient determination to familiarize with that code.

I think you are vastly overestimating the programming
abilities of many Python users.
The set of IT professionals includes a large number
of people who aren't programmers at all. The set of
programmers includes a large number of people who don't
know C. Even for someone who knows C, there are many
places in the Python code that require considerable
general knowlage of Python's overall architecure and
way of doing things that is not obtained without a fair
bit of time spent working with the code. I think your
existing familiarity with it is inteferring with your
ability to make an objective judgement of this.

To say a Python user should learn C, understand the
internals of Python sufficiently to create a patch as
a prerequisite to making a suggestion about how to
improve the user experience of Python, is, I personally
think, silly.
I take the same position for about any open-source software:
you *can* get into Apache, Mozilla, the Linux kernel,
and now the Java virtual machine if you want to. If you
don't, it's not because you can't, but because you don't
want to.

That's stretching the meaning of "want to" quite a bit.
Theere are lots of constraints on people that prevent
even the technically capapable of doing that. You can
write them off as not being sufficiently motivated if
you want, but I don't think that is being realistic.
Nor is it a good reason to disregard ideas for improving
Python coming from them.
It would be unrealistic (but not silly) to suggest that
if the source code weren't available at all. It is *not*
silly to suggest that people should make efforts to
contribute to open source software.

"Suggestion" covers a wide range of meanings. To
politely ask someone to consider submitting a patch
if they are able, with no implication of sanction
if they are not is one thing. To suggest that any
IT professional read and understand Python's internals
or be publically castigated is something else.

If I had meeting at work, and person X said I think
if department Y did things this way, we could save
$Z/year. Should I tell that person, "implement it
yourself, or be quiet". Sorry, I don't buy that.
 
R

rurpy

Robert said:
As I said, insult is in the ear of the listener, so I apologize if anyone
construed my comments as insults. However, facts are facts, and I stated them as
I believe them. If you can pick out the precise comments that you felt were
insulting, I will be happy to attempt clarifying them in a way that you do not
find insulting.

Facts?

As I explained in another post, "encouraging" someone to submit
a patch without a clue about the poster's abilities or resources
is offensive.
"begging for a fix on comp.lang.python is ..."
I didn't see the OP "begging" for anything.
"His suggestion that his time is worth more than that of anyone else..."
again (as the OP pointed out) no such claim was
made.
"and yes, you are being incredibly rude and insulting"
By responding in kind? I thought he was quite restrained
given the provocation.
"The way that you have been acting..."
Funny, I thought he was posting to c.l.p. Sounds like
he is a petulant 6 year old child.

In virtually every one of your posts you said things that
I certainly would have been offended by.
"You're also missing that *I'm trying to help you*"

I hope you understand that I'm trying to help *you*?

You don't need to bother clarifying, your meaning is clear.
It was the insulting tone you (and some others) expressed
that meaning in, while attacking the OP for being "rude"
that I found grossly unfair.
 
R

Robert Kern

Facts?

As I explained in another post, "encouraging" someone to submit
a patch without a clue about the poster's abilities or resources
is offensive.

I can't even begin to fathom that. I pointed him to the one path that will
(nearly) ensure that he gets the fix that he wants.
I didn't see the OP "begging" for anything.

As you wish. I'll admit that the choice of words had more emotional baggage than
perhaps the situation warranted. But you can't tell me that his choice of words
had any less. Or yours.
again (as the OP pointed out) no such claim was
made.

In your words, his "meaning is clear".
By responding in kind? I thought he was quite restrained
given the provocation.

Given that I don't understand how pointing him to appropriate actions to take to
get his feature request implemented is a provocation, I don't buy this one, either.
Funny, I thought he was posting to c.l.p. Sounds like
he is a petulant 6 year old child.

Pick any synonym you like, but I do believe that adults are capable of "acting".
I thought "act" was the least emotional and most appropriate of the bunch.
Perhaps I was wrong.
In virtually every one of your posts you said things that
I certainly would have been offended by.

I'll admit that you do seem easily offended.
I hope you understand that I'm trying to help *you*?

Yes, thank you. I specifically asked for clarification, and you provided it. I'm
not sure why you think that I wouldn't understand that. As Russ has been
fighting every practical suggestion (which I hope he can separate out from what
he believes are insults), I have no way of knowing that he understands that.

--
Robert Kern

"I have come to believe that the whole world is an enigma, a harmless enigma
that is made terrible by our own mad attempt to interpret it as though it had
an underlying truth."
-- Umberto Eco
 
J

James Stroud

Russ said:
Fredrik Lundh wrote:





And you didn't like the "tone" of some of my earlier posts?

Some people consider themselves above a sensible conversation.

James

--
James Stroud
UCLA-DOE Institute for Genomics and Proteomics
Box 951570
Los Angeles, CA 90095

http://www.jamesstroud.com/
 
J

James Stroud

Russ said:
Fredrik Lundh wrote:





And you didn't like the "tone" of some of my earlier posts?

Some people consider themselves above a sensible conversation.

James

--
James Stroud
UCLA-DOE Institute for Genomics and Proteomics
Box 951570
Los Angeles, CA 90095

http://www.jamesstroud.com/
 
O

OKB (not okblacke)

John said:
3. The OP asked only for values; you are asking for names and
values. If you have a magic flak jacket, please let me know; I'd
like to borrow it occasionally :)

On reflection I think my alternative suggestion might be just as
good: the interpreter could indicate the character position within the
line. This also handles cases where the operands aren't simple names.
(Not that I have any idea how much harder/easier this would be to
implement.)

I ask for names and values because that is what I want. If I have
some expression containing a bunch of variables and an exception is
raised, the most helpful information for me is the source code token
that is causing the error, because I can see the source code in my text
editor. The value is not as important, because there may be many
different variables that could be holding the same incorrect value. I
only want to look at the one that is ACTUALLY holding the incorrect
value.

--
--OKB (not okblacke)
Brendan Barnwell
"Do not follow where the path may lead. Go, instead, where there is
no path, and leave a trail."
--author unknown
 
R

Russ

Folks,

I'm truly sorry that so many feathers got ruffled in this thread. Let's
see if I can put this thing to rest gracefully.
My suggestion is trivial to implement and would benefit every Python
programmer (even if only slightly), so I don't think it is too much to
ask for.

Apparently I was wrong about the implementation being trivial. Tasks
often seem trivial -- until you actually try to do them. Yes, I should
have known better. Had I not wrote that little gem, I suppose a lot of
bad feelings could have been avoided.

Would it be nice to get the specifics about an index error? Yes. But is
it actually worth implementing? Well, since I have no intention of
implementing it myself, I can't make that call. I can only hope that
the Python maintainers decide that it is worth their effort to make
Python more convenient for the user. But even if they don't, I still
intend to continue using Python. The call is theirs to make. As I said
earlier, the "issue" is hardly a major one, and I'm sorry it got blown
out of proportion.

At this point I don't even plan to submit a formal request. I have too
many accounts and passwords already. If someone else wants to do it,
please have at it.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,774
Messages
2,569,599
Members
45,165
Latest member
JavierBrak
Top