-
Notifications
You must be signed in to change notification settings - Fork 462
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
Support defaultdict for namespace mapping #211
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -70,13 +70,16 @@ def __init__(self, | |
self.force_list = force_list | ||
|
||
def _build_name(self, full_name): | ||
if not self.namespaces: | ||
if self.namespaces is None: | ||
return full_name | ||
i = full_name.rfind(self.namespace_separator) | ||
if i == -1: | ||
return full_name | ||
namespace, name = full_name[:i], full_name[i+1:] | ||
short_namespace = self.namespaces.get(namespace, namespace) | ||
try: | ||
short_namespace = self.namespaces[namespace] | ||
except KeyError: | ||
short_namespace = namespace | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. From the documentation on
While a bit more verbose, this change uses |
||
if not short_namespace: | ||
return name | ||
else: | ||
|
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.
Although a
defaultdict
essentially has infinite items, until an item is actually inserted (either explicitly or on first access), it has zero length and evaluates toFalse
.