Skip to content
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

Closed
wants to merge 1 commit into from

Conversation

tongwei
Copy link
Contributor

@tongwei tongwei commented Dec 1, 2017

No description provided.

if isinstance(key_path, basestring):
_keys = key_path.split('.')

if _keys == [''] or _keys == ('',):
Copy link
Contributor

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[""][""][""]. 你觉得来?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

en

k=k, vars=vars))
else:
key = k
raise e
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

重新捕捉后的raise,直接写raise, 不加参数,可以保留原始的堆栈. 94行这样写就不造原始的e是哪里抛出的.

return k


def _replace_var_str(k):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

replace好像不太合适, 叫translate吧.

Copy link
Contributor

@drmingdrmer drmingdrmer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

代码没啥问题了.测试需要多考虑下边界条件和特殊情况啥的.

@@ -292,7 +292,7 @@ def test_getter_str(self):
('',
[''],
('',),
'lambda dic, vars={}: dic'
'lambda dic, vars={}: dic.get("", vars.get("_default", 0))'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

增加多个点的测试吧. "." "x." ".x.." 这些都应该是合法的.

@tongwei tongwei closed this Dec 4, 2017
@tongwei tongwei deleted the tongwei_dictutil_keypath branch December 4, 2017 05:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants