GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — decimal.getcontext() is not applied within bpython · Issue #918 · bpython/bpython

decimal.getcontext() is not applied within bpython #918

New issue
Copy link
New issue
Copy link
Open
Open
decimal.getcontext() is not applied within bpython#918
Copy link
Labels
bug

Description

@DorskFR
DorskFR
opened on Sep 27, 2021
Issue body actions

Steps to reproduce:

bpython version 0.21 on top of Python 3.9.6
>>> import decimal
>>> decimal.getcontext()
Context(prec=28, rounding=ROUND_HALF_EVEN, Emin=-999999, Emax=999999, capitals=1, clamp=0, flags=[], traps=[InvalidOperation, DivisionByZero, Overflow])
>>> decimal.getcontext().rounding = decimal.ROUND_HALF_UP 
>>> decimal.getcontext()
Context(prec=28, rounding=ROUND_HALF_EVEN, Emin=-999999, Emax=999999, capitals=1, clamp=0, flags=[], traps=[InvalidOperation, DivisionByZero, Overflow])
>>> 

expected the rounding to be changed.
also fails using setcontext()

Reacted by Arseniy Terekhin and Laurynas Alekna

Activity

  1. thomasballinger commented on Sep 27, 2021

    @thomasballinger
    thomasballinger
    on Sep 27, 2021
    Member
    More actions

    Yikes, that's too bad. Apparently this is a "coroutine-local" thing? So guessing switching from greenlets to threads might not fix, instead it would take moving to async?

    Maybe we should manually persist this between execution contexts? I want to learn more about coroutine-locals.

  2. thomasballinger commented on Sep 27, 2021

    @thomasballinger
    thomasballinger
    on Sep 27, 2021
    Member
    More actions

    This works in Python 3.6 and is broken in 3.7+.

  3. sebastinas commented on Sep 27, 2021

    @sebastinas
    sebastinas
    on Sep 27, 2021
    Contributor
    More actions

    Why wouldn't this work if we switch to threads? All the user code that is executed would be in exactly one thread.

  4. thomasballinger commented on Sep 27, 2021

    @thomasballinger
    thomasballinger
    on Sep 27, 2021
    Member
    More actions

    Maybe it will, I meant to say I don't know if it will or not because it's not a thread local, it's something else.

  5. sebastinas commented on Sep 27, 2021

    @sebastinas
    sebastinas
    on Sep 27, 2021
    Contributor
    More actions

    I'm not sure I can follow. The context is thread-local.

  6. thomasballinger commented on Sep 27, 2021

    @thomasballinger
    thomasballinger
    on Sep 27, 2021
    Member
    More actions

    I don't really understand what a coroutine local is yet, but I think it's now sometimes (usually?) a coroutine-local instead based on the value of decimal.HAVE_CONTEXTVAR. Edit: reading more, it sounds like coroutine–locals (contexts) work with threads and additionally work with coroutines, so I think this distinction is not important here (unless we do something with coroutines).

  7. sebastinas
    added
    bug
    on Oct 12, 2021
  8. nicolaiarocci commented on Jun 6, 2023

    @nicolaiarocci
    nicolaiarocci
    on Jun 6, 2023
    More actions

    Still needing help with Python 3.11.3. A workaround that might not apply to everyone is resorting to DefaultContext which works as expected:

    bpython version 0.24 on top of Python 3.11.3
    >>> import decimal
    >>> decimal.getcontext().prec = 6
    >>> decimal.Decimal(1) / decimal.Decimal(7)
    Decimal('0.1428571428571428571428571429')
    
    >>> decimal.DefaultContext.prec = 6
    >>> decimal.Decimal(1) / decimal.Decimal(7)
    Decimal('0.142857')
    Reacted by Arseniy Terekhin and Laurynas Alekna
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402503 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.