-
-
Notifications
You must be signed in to change notification settings - Fork 167
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 building query without values #307
Comments
Right now I'm inclining to agree with your proposal but want to check it again for controversy. Would you prepare a PR for review? |
@asvetlov it could be a special constant: # in yarl:
QUERY_KEY_WITHOUT_VALUE = object()
# in code:
from yarl import QUERY_KEY_WITHOUT_VALUE
url = URL('https://api.crowdin.com/api/project/{project-identifier}/pre-translate')
url = url.with_query(key=project_key, json=QUERY_KEY_WITHOUT_VALUE) It's more obvious, but IMHO more ugly. I can prepare a PR tomorrow. |
Agree, a constant is worse than just None |
As well as it does not distinguish the
If you want to create a query with non-standard representation (parameters without url = url.with_query(key=project_key)
url = url.with_query(url.query_string + '&json') |
Sometimes query consists not only of pairs of keys and values but also can contain standalone keys. In my opinion, it's bad, but I encountered this a few times in different APIs.
For example, I need to build a URL like: https://api.crowdin.com/api/project/{project_identifier}/pre-translate?key={project_key}&json (see https://support.crowdin.com/api/pre-translate/ for details).
I propose to make an interface look like this:
This is safe because now passing
None
as keyword argument value raisesTypeError
. If user wants to get an URL withjson=
(note that the last symbol is the equals sign), he passesjson=''
as he does now.The text was updated successfully, but these errors were encountered: