Pro!

sentinel object trick, to avoid the tricky error of a mutable default argument

_default_skip_tags_sentinel = object()

_default_skip_tags = ['pre']

def elem_strip_all_text(
parent_e,
chars=" \r\n\t",
skip_tags=_default_skip_tags_sentinel,
grandparent_tag_hint=None,
):

...

if skip_tags is _default_skip_tags_sentinel:
skip_tags = _default_skip_tags
if skip_tags is None:
skip_tags = []

...

Forward

2 months, 1 week ago by Manuel "Moe" G. - Pro!

Add a Reply

Join Now to Reply!

To add your own reply, sign in or join Pownce today!

This note is also available to the general public.