Opened 8 years ago

Last modified 7 years ago

#14795 new task

Mutable defaults in function/method definitions

Reported by: mguaypaq Owned by: mguaypaq
Priority: minor Milestone: sage-6.4
Component: misc Keywords:
Cc: Merged in:
Authors: Mathieu Guay-Paquet Reviewers:
Report Upstream: N/A Work issues:
Branch: Commit:
Dependencies: Stopgaps:

Status badges


Several functions and methods in Sage have mutable default arguments, especially lists. This is generally frowned upon, at least on the Python side (see, since it can cause so many subtle bugs, and there's usually no benefit to doing this instead of using a tuple or None (with creation of the mutable argument in the function body).

Are there any objections to fixing this?

Here is a somewhat filtered (and certainly non-exhaustive) output of a naive grep search through the codebase:

sage/combinat/    def content(self, r, c, multicharge=[0]):
sage/combinat/    def dimension(self, smaller = [], k = 1):
sage/combinat/root_system/    def __classcall__(cls, W, min_length = 0, max_length = infinity, min_support = frozenset([]), max_support = None):
sage/combinat/root_system/        def plot(self, size=[[0],[0]], projection='usual', simple_roots=True, fundamental_weights=True, alcovewalks=[]):
sage/combinat/    def content(self, k, multicharge=[0]):
sage/combinat/designs/    def __init__(self, v=0, k=0, t=0, size=0, points=[], blocks=[], low_bd=0, method='', creator ='',timestamp=''):
sage/combinat/ _slider01(A, t, k, p1, p2, fixedcols=[]):
sage/plot/    def _extract_kwds_for_show(cls, kwds, ignore=[]):
sage/matrix/ report(F, title, systems = ['sage', 'magma'], **kwds):
sage/server/notebook/    def do_sage_extensions_preparsing(self, s, files_seen_so_far=[], this_file=''):
sage/sets/ Family(indices, function = None, hidden_keys = [], hidden_function = None, lazy = False, name=None):
sage/modular/ eta_poly_relations(eta_elements, degree, labels=['x1','x2'], verbose=False):
sage/modular/modform/    def generators(self, maxweight=8, prec=10, start_gens=[], start_weight=2):
sage/modular/modform/    def gen_forms(self, maxweight=8, start_gens=[], start_weight=2):
sage/quadratic_forms/ random_quadraticform(R, n, rand_arg_list=[]):
sage/quadratic_forms/ random_quadraticform_with_conditions(R, n, condition_list=[], rand_arg_list=[]):
sage/groups/perm_gps/ color_of_square(facet, colors=['lpurple', 'yellow', 'red', 'green', 'orange', 'blue']):
sage/groups/perm_gps/    def plot_cube(self, mv, title=True, colors = [lpurple, yellow, red, green, orange, blue]):
sage/groups/perm_gps/    def __init__(self, state=None, history=[], colors=[lpurple,yellow,red,green,orange,blue]):
sage/rings/number_field/ enumerate_totallyreal_fields_rel(F, m, B, a = [], verbose=0, return_seqs=False):
sage/rings/number_field/    def invertible_residues_mod(self, subgp_gens=[], reduce=True):
sage/rings/polynomial/    def __init__(self, gfan_polyhedral_fan, parameter_indices = []):
sage/rings/polynomial/    def __init__(self, gfan_polyhedral_fan, polynomial_system, poly_ring, parameters = []):
sage/rings/polynomial/    def tropical_intersection(self, parameters = [], symmetry_generators = [], *args, **kwds):
sage/geometry/    def convex_hull(self, points=[]):
sage/doctest/    def __init__(self, source, options, funclist=[]):
sage/homology/    def __init__(self, maximal_faces=[], **kwds):
sage/interfaces/    def function_call(self, function, args=[], params={}, nvals=1):
sage/interfaces/    def __init__(self, formula, vars, qvars=[]):
sage/interfaces/    def __call__(self, action, input=None, options=[], verbose=False):
sage/misc/ containing_block(code, ix, delimiters=['()','[]','{}'], require_delim=True):
sage/misc/    def run(self, category = None, skip = [], catch = True, raise_on_failure = False, **options):
sage/misc/    def __init__(self, bb=False, delimiters=["(", ")"]):
sage/misc/    def __init__(self, systems=[], verbose=False):
sage/schemes/elliptic_curves/ is_possible_j(j,S=[]):
sage/schemes/elliptic_curves/ egros_from_j_1728(S=[]): 
sage/schemes/elliptic_curves/ egros_from_j_0(S=[]):
sage/schemes/elliptic_curves/ egros_from_j(j,S=[]): 
sage/schemes/elliptic_curves/ egros_from_jlist(jlist,S=[]): 
sage/schemes/elliptic_curves/ egros_get_j(S=[], proof=None, verbose=False):
sage/schemes/elliptic_curves/ EllipticCurves_with_good_reduction_outside_S(S=[], proof=None, verbose=False):
sage/schemes/elliptic_curves/    def regulator_of_points(self, points=[], precision=None):
sage/schemes/elliptic_curves/    def has_good_reduction_outside_S(self,S=[]):

Change History (3)

comment:1 Changed 8 years ago by vbraun_spam

  • Milestone changed from sage-6.1 to sage-6.2

comment:2 Changed 7 years ago by vbraun_spam

  • Milestone changed from sage-6.2 to sage-6.3

comment:3 Changed 7 years ago by vbraun_spam

  • Milestone changed from sage-6.3 to sage-6.4
Note: See TracTickets for help on using tickets.