-
Notifications
You must be signed in to change notification settings - Fork 85
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Deprecate get_value_by_key_path
and replace with xpath_search
#626
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like a good change. Thanks 👍
src/fundus/parser/data.py
Outdated
def xpath_search(self, query: Union[XPath, str], scalar: Literal[True] = True) -> Optional[Any]: | ||
... | ||
|
||
def xpath_search(self, query: Union[XPath, str], scalar: bool = False) -> Union[Any, List[Any]]: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not being that familiar with typing, is this third variation necessary for the case where a variable value is passed to scalar? So it's undetermined at compilation, whether it will be True or False?
Also, if this is the case, shouldn't the return value also be Union[Optional[Any], List[Any]]
, to be consistent with the case of Literal[True]?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, you don't have to type hint the original function, it's just for IDEs like Pycharm.
You're right, I forgot the Optional
there.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good 👍
This PR deprecates
get_value_by_key_path
class method ofLinkedDataMapping
and replaces all existing occasions withxpath_search
.To talk about efficiency I provide some additional runtime comparison and a script to reproduce.
The script loads one article for
The West Australian
, since it by far includes the largestLD
and loads a specific value (or key path) 100000 times. For more details click onScript
.Script
Output
For better typing, this PR adds a
scalar
parameter toxpath_search
, indicating that one expects an optional scalar value in return.