Opened 6 years ago
Last modified 4 years ago
#16969 new PLEASE CHANGE
Missing error message for WordMorphism
Reported by: | nadialafreniere | Owned by: | |
---|---|---|---|
Priority: | major | Milestone: | sage-6.4 |
Component: | PLEASE CHANGE | Keywords: | error, Words |
Cc: | slabbe, tmonteil | Merged in: | |
Authors: | Nadia Lafrenière | Reviewers: | |
Report Upstream: | N/A | Work issues: | |
Branch: | Commit: | ||
Dependencies: | Stopgaps: |
Description
The error message should be better:
sage: m=WordMorphism('0->1,1->0') sage: m([0]) Traceback (most recent call last): ... KeyError: 0
Change History (3)
comment:1 Changed 6 years ago by
comment:2 Changed 6 years ago by
I suggested Nadia to create the ticket. For some user the difference between the str '0'
and the int 0
is not clear especially since both of the following have the same repr :
sage: m = WordMorphism('0->01,1->10'); m WordMorphism: 0->01, 1->10 sage: m = WordMorphism({0:[0,1],1:[1,0]}); m WordMorphism: 0->01, 1->10
The following is fine and I think any user is okay with it:
sage: m WordMorphism: 0->01, 1->10 sage: m([4]) Traceback (most recent call last): ... KeyError: 4
But suppose you don't remember how m
was created. You print it and then you use it:
sage: m WordMorphism: 0->01, 1->10 sage: m([0]) Traceback (most recent call last): ... KeyError: 0
The first time you get the error, it can be confusing and not easy to find what is wrong.
I was thinking about a better error message like the following:
sage: m WordMorphism: 0->01, 1->10 sage: m([0]) Traceback (most recent call last): ... KeyError: 0. Valid keys are ['0', '1'].
comment:3 Changed 4 years ago by
- Cc tmonteil added
Note: See
TracTickets for help on using
tickets.
The error message is consistent with what Python gives:
so I would close it as "invalid" (not a bug).
Interestingly,
KeyError
uses therepr()
of its argument to show the exception, while other exceptions use thestr()
, note the extra'
around the last0
:So I really think that
KeyError
is supposed to take as argument the exact key which failed.