Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGES/1645.doc.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Added a note in the :meth:`~yarl.URL.with_query` documentation explaining
that types implementing ``__int__`` (e.g. :class:`~uuid.UUID`) are
converted to integers, and advising users to cast to :class:`str` when the
human-readable representation is needed.
14 changes: 14 additions & 0 deletions docs/api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -696,6 +696,20 @@ section generates a new :class:`URL` instance.
Please see :ref:`yarl-bools-support` for the reason why :class:`bool` is not
supported out-of-the-box.

.. tip::

Types that implement :meth:`~object.__int__` (e.g. :class:`~uuid.UUID`)
are converted to integers because :class:`int` is preferred over
:class:`str` for numeric coercion. If you need the human-readable
representation, cast the value to :class:`str` before passing it:

.. doctest::

>>> import uuid
>>> uid = uuid.UUID('3199712f-1b78-4420-852b-a73ee09e6a8f')
>>> URL('http://example.com/').with_query({'id': str(uid)})
URL('http://example.com/?id=3199712f-1b78-4420-852b-a73ee09e6a8f')

.. doctest::

>>> URL('http://example.com/path?a=b').with_query('c=d')
Expand Down
Loading