Last active
October 4, 2022 03:10
-
-
Save dogweather/c7a4b43df32a18ec193ada95fa2dc326 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# | |
# 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