-
Notifications
You must be signed in to change notification settings - Fork 9
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
add dict_util key_path
tuple and list support
#164
Conversation
dictutil/dictutil.py
Outdated
if isinstance(key_path, basestring): | ||
_keys = key_path.split('.') | ||
|
||
if _keys == [''] or _keys == ('',): |
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.
如果_keys
不是split出来的,空字符串应该是个正确的输入..
想了下, 如果输入的key_path是空串好像也应该是个正确的输入, 这些都应该是正确的: "", ".", ".."
分别表示:x[""], x[""][""], x[""][""][""]
. 你觉得来?
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.
en
dictutil/dictutil.py
Outdated
k=k, vars=vars)) | ||
else: | ||
key = k | ||
raise e |
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.
重新捕捉后的raise,直接写raise
, 不加参数,可以保留原始的堆栈. 94行这样写就不造原始的e是哪里抛出的.
dictutil/dictutil.py
Outdated
return k | ||
|
||
|
||
def _replace_var_str(k): |
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.
replace好像不太合适, 叫translate吧.
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.
代码没啥问题了.测试需要多考虑下边界条件和特殊情况啥的.
dictutil/test/test_dictutil.py
Outdated
@@ -292,7 +292,7 @@ def test_getter_str(self): | |||
('', | |||
[''], | |||
('',), | |||
'lambda dic, vars={}: dic' | |||
'lambda dic, vars={}: dic.get("", vars.get("_default", 0))' |
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.
增加多个点的测试吧. "." "x." ".x.."
这些都应该是合法的.
9cdac8f
to
f249847
Compare
No description provided.