Opened 6 years ago
Closed 6 years ago
#22271 closed enhancement (fixed)
py3 prepare some cases of zip behaviour
Reported by: | Frédéric Chapoton | Owned by: | |
---|---|---|---|
Priority: | major | Milestone: | sage-7.6 |
Component: | python3 | Keywords: | |
Cc: | Merged in: | ||
Authors: | Frédéric Chapoton | Reviewers: | Jeroen Demeyer |
Report Upstream: | N/A | Work issues: | |
Branch: | bbe4117 (Commits, GitHub, GitLab) | Commit: | bbe41176db974f43f5e28c99bb28fdb817f65332 |
Dependencies: | Stopgaps: |
Description
as another step to py3
- take care of a reversed(zip()) in crystals
- make sure that factorizations can handle iterators
Change History (10)
comment:1 Changed 6 years ago by
Branch: | → u/chapoton/22271 |
---|---|
Commit: | → 3ba3a01e150ebf53e87d8fb80a2ac73e5bab1b17 |
Status: | new → needs_review |
comment:2 Changed 6 years ago by
As a general principle, I don't like code of the form
try: do_something() except E: raise E("msg")
Especially if msg
is meaningless or plain wrong. Just replace it by
do_something()
(I am talking about the raise TypeError("x must be a list")
and also raise TypeError("exponents of factors must be integers")
)
comment:3 Changed 6 years ago by
Status: | needs_review → needs_work |
---|
In this case, you probably don't need the conversion to list
at all, since enumerate()
can handle iterables. This works without conversion to list:
sage: list(enumerate(xrange(5))) [(0, 0), (1, 1), (2, 2), (3, 3), (4, 4)]
comment:4 Changed 6 years ago by
Thinking even more about it, why not replace this whole block
if not isinstance(x, (list, tuple)): try: x = list(x) except TypeError: raise TypeError("x must be a list") for i, t in enumerate(x): if not (isinstance(t, tuple) and len(t) == 2): raise TypeError("x must be a list of pairs (p, e) with e an integer") try: x[i] = (t[0], Integer(t[1])) except TypeError: raise TypeError("exponents of factors must be integers")
by the one-liner
x = [(p, Integer(e)) for (p,e) in x]
comment:5 Changed 6 years ago by
Commit: | 3ba3a01e150ebf53e87d8fb80a2ac73e5bab1b17 → bbe41176db974f43f5e28c99bb28fdb817f65332 |
---|
Branch pushed to git repo; I updated commit sha1. New commits:
bbe4117 | trac 22271 code simplified
|
comment:9 Changed 6 years ago by
Reviewers: | → Jeroen Demeyer |
---|---|
Status: | needs_review → positive_review |
comment:10 Changed 6 years ago by
Branch: | u/chapoton/22271 → bbe41176db974f43f5e28c99bb28fdb817f65332 |
---|---|
Resolution: | → fixed |
Status: | positive_review → closed |
Note: See
TracTickets for help on using
tickets.
New commits:
py3: handle some cases of zip behaviour