Skip to content

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

@Feuermurmel

Description

@Feuermurmel

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    docsDocumentation in the Doc direasy

    Projects

    Status

    Todo

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions