post recipient view lookup logic#103
Conversation
|
Nice ! |
| for key in ('email', 'userName', 'userId'): | ||
| # ignore empty values; they won't help with a lookup | ||
| if locals()[key]: | ||
| data[key] = locals()[key] |
There was a problem hiding this comment.
Using locals() here might seem a bit overkill, but...
Other ways to achive the same result:
- Manually write a dict - but it means one has to write both keys and values and it's a bit ugly (beautiful is better than ugly)
user_info = [("userName", userName), ("userId", userId), ("email", email)]
data.update({key: value for key, value in user_info if value})- Change these 3 values to **kwargs in the function call (as they're not used elsewhere) - but that's breaking the API (is it a public facing API ?).
Using locals is not problematic at all, but it's less "straightfoward code". Thing is, we're using local to help us change a kinda ugly 1 line simple code into a purer 4 line more complex code. Maybe it could be a case of "practicality beats purity"...
EDIT: After reading both your code and the snippet above, I'm not even convinced that mine would be any better actually.
There was a problem hiding this comment.
@ewjoachim yeah, i don't love using locals but also wasn't satisfied with any other option i could think of which would avoid changing the function signature...
|
@zebuline i can put tests on my list, but i probably won't get to them soon |
This will use
clientUserId+userIdto lookup a recipient ifuserIdis available, elseclientUserId+email+userName. It also removesenvelopeIdfrom the lookup kwargs because i believe that value is ignored, and it is already used in the url endpoint path anyway.fixes #102