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

Docs: decimal.BasicContext etc. are not classes #128349

Closed
Feuermurmel opened this issue Dec 30, 2024 · 3 comments · Fixed by #128379
Closed

Docs: decimal.BasicContext etc. are not classes #128349

Feuermurmel opened this issue Dec 30, 2024 · 3 comments · Fixed by #128379
Labels
docs Documentation in the Doc dir easy

Comments

@Feuermurmel
Copy link

Feuermurmel commented Dec 30, 2024

Documentation

The decimal module exports three constants BasicContext, ExtendedContext and DefaultContext, which are instances of Context:

$ python3
Python 3.13.1 (main, Dec 20 2024, 10:15:12) [Clang 14.0.0 (clang-1400.0.29.202)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import decimal
>>> type(decimal.BasicContext)
<class 'decimal.Context'>

The documentation of module decimal is misleading by containing these 3 declarations:

class decimal.BasicContext
        ...

class decimal.ExtendedContext
        ...

class decimal.DefaultContext
        ...

This made me think that these are subclasses of Context that need to be instantiated like this:

>>> decimal.setcontext(decimal.ExtendedContext())
Traceback (most recent call last):
  File "<python-input-2>", line 1, in <module>
    decimal.setcontext(decimal.ExtendedContext())
                       ~~~~~~~~~~~~~~~~~~~~~~~^^
TypeError: 'decimal.Context' object is not callable

I would expect the declarations to look more like the ones e.g. under Rounding modes.

Linked PRs

@Feuermurmel Feuermurmel added the docs Documentation in the Doc dir label Dec 30, 2024
@terryjreedy
Copy link
Member

terryjreedy commented Dec 30, 2024

@rhettinger decimal expert

@skirpichev
Copy link
Member

This looks as a bug for me, indeed:

>>> inspect.isclass(decimal.BasicContext)
False
>>> inspect.isclass(decimal.Context)
True

BTW, in the sphinx docs BasicContext referenced with const prefix.

@picnixz
Copy link
Member

picnixz commented Dec 31, 2024

We should change .. class:: into .. data:: (especially, if we are referencing them using the :const: role). Note that we say:

In addition to the three supplied contexts, new contexts can be created with the Context constructor.

So we should assume that these are not meant to be classes at all (if someone was wondering whether they could act as such)

@picnixz picnixz added the easy label Dec 31, 2024
Eclips4 pushed a commit that referenced this issue Jan 2, 2025
miss-islington pushed a commit to miss-islington/cpython that referenced this issue Jan 2, 2025
…ned decimal `Context` objects (pythonGH-128379)

(cherry picked from commit 60c6518)

Co-authored-by: abkmystery <36216019+abkmystery@users.noreply.github.com>
miss-islington pushed a commit to miss-islington/cpython that referenced this issue Jan 2, 2025
…ned decimal `Context` objects (pythonGH-128379)

(cherry picked from commit 60c6518)

Co-authored-by: abkmystery <36216019+abkmystery@users.noreply.github.com>
Eclips4 pushed a commit that referenced this issue Jan 2, 2025
…ined decimal `Context` objects (GH-128379) (#128401)

gh-128349: Use `.. data::` instead of `.. class::` for pre-defined decimal `Context` objects (GH-128379)
(cherry picked from commit 60c6518)

Co-authored-by: abkmystery <36216019+abkmystery@users.noreply.github.com>
Eclips4 pushed a commit that referenced this issue Jan 2, 2025
…ined decimal `Context` objects (GH-128379) (#128402)

gh-128349: Use `.. data::` instead of `.. class::` for pre-defined decimal `Context` objects (GH-128379)
(cherry picked from commit 60c6518)

Co-authored-by: abkmystery <36216019+abkmystery@users.noreply.github.com>
srinivasreddy pushed a commit to srinivasreddy/cpython that referenced this issue Jan 8, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs Documentation in the Doc dir easy
Projects
Status: Todo
4 participants