Skip to content

Commit

Permalink
Improve parameter description update on copy.
Browse files Browse the repository at this point in the history
  • Loading branch information
riga committed Dec 13, 2024
1 parent 499d406 commit b5be40c
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions law/patches.py
Original file line number Diff line number Diff line change
Expand Up @@ -460,6 +460,8 @@ def patch_parameter_copy():
functionality will eventually be moved to luigi, but the patch might be kept for versions of
luigi where it was not addded yet.
"""
default_cre = re.compile(r"(.+)(;|,)\s*((empty|no|without) default|default: [^\;]+)\s*$")

def _copy(self, add_default_to_description=False, **kwargs):
# copy the instance
inst = copy.copy(self)
Expand All @@ -476,8 +478,13 @@ def _copy(self, add_default_to_description=False, **kwargs):

# amend the description
if add_default_to_description:
prefix = "; " if inst.description else ""
inst.description += "{}default: {}".format(prefix, inst._default)
# remove default from description
if inst.description:
m = default_cre.match(inst.description)
if m:
inst.description = m.group(1)
inst.description += "; "
inst.description += "default: {}".format(inst._default)

return inst

Expand Down

0 comments on commit b5be40c

Please sign in to comment.