Skip to content

Instantly share code, notes, and snippets.

@dogweather
Created October 4, 2022 02:51
Show Gist options
  • Save dogweather/e717ce5c13c315ebe8d209249a69f76a to your computer and use it in GitHub Desktop.
Save dogweather/e717ce5c13c315ebe8d209249a69f76a to your computer and use it in GitHub Desktop.
# Original
def first(node, css, expected):
result = str(node.css(css).get())
if result is None:
raise ParseException(f"Could not parse the {expected}")
return result
# Refactored
def first(node, css, expected) -> str:
match node.css(css).get():
case str(result):
return result
case _:
raise ParseException(f"Could not parse the {expected}")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment