Opened 2 years ago
Closed 2 years ago
#29797 closed defect (fixed)
sage.misc.defaults.variable_names return tuple in all cases
Reported by:  heluani  Owned by:  

Priority:  major  Milestone:  sage9.2 
Component:  misc  Keywords:  
Cc:  Merged in:  
Authors:  Reimundo Heluani  Reviewers:  Travis Scrimshaw 
Report Upstream:  N/A  Work issues:  
Branch:  725d4b5 (Commits, GitHub, GitLab)  Commit:  725d4b5978a92f4ecf3b46911b16d0443c1af616 
Dependencies:  Stopgaps: 
Description (last modified by )
sage.misc.defaults.variable_names and latex_variable_names return tuple if the number of variable names requested is bigger than 1 or 0 and a list if it's 1. This ticket fixes that.
Change History (10)
comment:1 Changed 2 years ago by
 Branch set to u/heluani/sage_misc_defaults_variable_names_return_tuple_in_all_cases
comment:2 Changed 2 years ago by
 Commit set to 15704692e56d905577f721a4e0f53898f24e7107
 Component changed from PLEASE CHANGE to misc
 Description modified (diff)
 Status changed from new to needs_review
 Type changed from PLEASE CHANGE to defect
comment:3 followup: ↓ 7 Changed 2 years ago by
 Reviewers set to Travis Scrimshaw
comment:4 followup: ↓ 5 Changed 2 years ago by
Thanks for making the fix, but I think there are space characters at the ends of some lines (and a line with only spaces). Please get rid of those spaces. Also, since you are editing the file, please change tuple([ ... ])
to tuple( ... )
(twice, near the end of both functions), even though this is not your fault.
comment:5 in reply to: ↑ 4 ; followup: ↓ 8 Changed 2 years ago by
Replying to ghDaveWitteMorris:
Also, since you are editing the file, please change
tuple([ ... ])
totuple( ... )
(twice, near the end of both functions), even though this is not your fault.
I am 1 on this change because it is actually slower (surprisingly) to not have the inner list comprehension.
comment:6 Changed 2 years ago by
 Commit changed from 15704692e56d905577f721a4e0f53898f24e7107 to 725d4b5978a92f4ecf3b46911b16d0443c1af616
Branch pushed to git repo; I updated commit sha1. New commits:
725d4b5  Changes requested by comments #3 and #4

comment:7 in reply to: ↑ 3 Changed 2 years ago by
 Status changed from needs_review to positive_review
Replying to tscrim:
Once changed, you can set a positive review on my behalf.
Was I suppose to make this change to 'positive review'?
comment:8 in reply to: ↑ 5 Changed 2 years ago by
Replying to tscrim:
I am 1 on this change because it is actually slower (surprisingly) to not have the inner list comprehension.
Indeed! There's no "tuple comprehension" in python; just the possibility to make a tuple from an iterator. You can save the "tuple" by writing
(*[...],)
but as far as I can see this has about the same performance as tuple([...])
has. I guess the tuple constructor misses some of the optimizations of list comprehensions to build a list with beforehandunknownlength. Passing a list into tuple gives the length beforehand, so it's easier to construct the tuple efficiently.
comment:9 Changed 2 years ago by
OK, I stand corrected. I made the suggestion because it was a reviewer comment on one of the patches I wrote, and made sense to me. (I did some quick tests on this case and I am usually not seeing any significant difference in performance, but tuple([...])
does come out faster sometimes, and I can believe that it is a better general practice, even though it is counterintuitive.)
comment:10 Changed 2 years ago by
 Branch changed from u/heluani/sage_misc_defaults_variable_names_return_tuple_in_all_cases to 725d4b5978a92f4ecf3b46911b16d0443c1af616
 Resolution set to fixed
 Status changed from positive_review to closed
For safety:
Also, minor nitpick with the doc formatting:
Once changed, you can set a positive review on my behalf.