Created
October 4, 2022 02:51
-
-
Save dogweather/e717ce5c13c315ebe8d209249a69f76a 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 | |
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