Skip to content

Instantly share code, notes, and snippets.

@dogweather
Last active October 4, 2022 03:10
Show Gist options
  • Save dogweather/c7a4b43df32a18ec193ada95fa2dc326 to your computer and use it in GitHub Desktop.
Save dogweather/c7a4b43df32a18ec193ada95fa2dc326 to your computer and use it in GitHub Desktop.
#
# Original
#
dl_lists: list[Any] = html.css("main dl")
if len(dl_lists) > 0 and isinstance(dl_lists[0], Selector):
first_dl_list = dl_lists[0]
else:
raise ParseException("Expected a <dl>")
#
# Refactored
#
match html.css("main dl"):
case [first, *_] if isinstance(first, Selector):
first_dl_list = first
case _:
raise ParseException("Expected a <dl>")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment