FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

gh-142108: Document Decimal formatting behavior differences by Yashp002 · Pull Request #142117 · python/cpython · GitHub

Repository navigation

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .rst  (3) All 1 file type selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
41 changes: 41 additions & 0 deletions Doc/c-api/descriptor.rst
Show comments Show annotations View file Open in desktop
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,45 @@
.. c:function:: PyObject* PyDescr_NewMember(PyTypeObject *type, struct PyMemberDef *meth)


.. c:var:: PyTypeObject PyMemberDescr_Type

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Changes in Doc/c-api/ are not related to this pr, please revert.


The type object for member descriptor objects created from
:c:type:`PyMemberDef` structures. These descriptors expose fields of a
C struct as attributes on a type, and correspond to :class:`types.MemberDescriptorType`
objects in the Python layer.


.. c:var:: PyTypeObject PyGetSetDescr_Type

The type object for get/set descriptor objects created from
:c:type:`PyGetSetDef` structures. These descriptors implement attributes
whose value is computed by C getter and setter functions, and are used
for many built-in type attributes.


.. c:function:: PyObject* PyDescr_NewMethod(PyTypeObject *type, struct PyMethodDef *meth)


.. c:var:: PyTypeObject PyMethodDescr_Type

The type object for method descriptor objects created from
:c:type:`PyMethodDef` structures. These descriptors expose C functions as
methods on a type, and correspond to :class:`types.MemberDescriptorType` objects in the
Python layer.


.. c:function:: PyObject* PyDescr_NewWrapper(PyTypeObject *type, struct wrapperbase *wrapper, void *wrapped)

Check warning on line 51 in Doc/c-api/descriptor.rst

View workflow job for this annotation

GitHub Actions / Docs / Docs

c:identifier reference target not found: wrapperbase [ref.identifier]


.. c:var:: PyTypeObject PyWrapperDescr_Type

The type object for wrapper descriptor objects created by
:c:func:`PyDescr_NewWrapper` and :c:func:`PyWrapper_New`. Wrapper
descriptors are used internally to expose special methods implemented
via wrapper structures, and appear in Python as :class:`types.WrapperDescriptorType`
objects.


.. c:function:: PyObject* PyDescr_NewClassMethod(PyTypeObject *type, PyMethodDef *method)


Expand Down Expand Up @@ -55,6 +88,14 @@
:class:`classmethod` in the Python layer.


.. c:var:: PyTypeObject PyClassMethodDescr_Type

The type object for C-level class method descriptor objects.
This is the type of the descriptors created for :func:`classmethod` defined in C
extension types, and is the same object as :class:`classmethod` in the
Python layer.


.. c:function:: PyObject *PyClassMethod_New(PyObject *callable)

Create a new :class:`classmethod` object wrapping *callable*.
Expand Down
11 changes: 11 additions & 0 deletions Doc/c-api/dict.rst
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,17 @@ Dictionary Objects
prevent modification of the dictionary for non-dynamic class types.


.. c:var:: PyTypeObject PyDictProxy_Type

The type object for mapping proxy objects created by
:c:func:`PyDictProxy_New` and for the read-only ``__dict__`` attribute
of many built-in types. A :c:type:`PyDictProxy_Type` instance provides a
dynamic, read-only view of an underlying dictionary: changes to the
underlying dictionary are reflected in the proxy, but the proxy itself
does not support mutation operations.These objects correspond to
:class:`types.MappingProxyType` in Python.


.. c:function:: void PyDict_Clear(PyObject *p)

Empty an existing dictionary of all key-value pairs.
Expand Down
14 changes: 14 additions & 0 deletions Doc/library/string.rst
Show comments Show annotations View file Open in desktop
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -629,6 +629,20 @@
of the :func:`round` builtin. For :class:`~decimal.Decimal`, the rounding
mode of the current :ref:`context <decimal-context>` will be used.


.. note::

The :class:`~decimal.Decimal` type has special formatting behavior:

* When using ``__format__`` (f-strings, ``format()``, ``str.format()``),
Decimal formats with maximum precision only when precision is **omitted**

Check warning on line 638 in Doc/library/string.rst

View workflow job for this annotation

GitHub Actions / Docs / Docs

Bullet list ends without a blank line; unexpected unindent. [docutils]
Comment on lines +637 to +638

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

This is already documented, please revert. Also, the whole section of documentation is about string formatting, it's pointless to say that you are using __format__().

in ``f``, ``e``, or ``g`` format types. If precision is explicitly specified,
it is respected.

* When using ``%`` formatting (old-style string formatting with the ``%`` operator),
Decimal values are first converted to :class:`float`, which may result in

Check warning on line 643 in Doc/library/string.rst

View workflow job for this annotation

GitHub Actions / Docs / Docs

Bullet list ends without a blank line; unexpected unindent. [docutils]
Comment on lines +642 to +643

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality
  1. This note not belongs to this section, it's about printf-like formatting.
  2. In the issue thread it was explained, that there is nothing special about Decimal's here. If we have to document something, it should be about behavior of printf-like formatting for non-builtin types.

precision loss.

The available presentation types for :class:`complex` are the same as those for
:class:`float` (``'%'`` is not allowed). Both the real and imaginary components
of a complex number are formatted as floating-point numbers, according to the
Expand Down
Loading

Back | FazBrowse Home | New Git URL