@@ -436,75 +436,34 @@ class FloatOperation(DecimalException, TypeError):
436
436
# work for older Pythons. If threads are not part of the build, create a
437
437
# mock threading object with threading.local() returning the module namespace.
438
438
439
- try :
440
- import threading
441
- except ImportError :
442
- # Python was compiled without threads; create a mock object instead
443
- class MockThreading (object ):
444
- def local (self , sys = sys ):
445
- return sys .modules [__xname__ ]
446
- threading = MockThreading ()
447
- del MockThreading
448
-
449
- try :
450
- threading .local
451
-
452
- except AttributeError :
453
-
454
- # To fix reloading, force it to create a new context
455
- # Old contexts have different exceptions in their dicts, making problems.
456
- if hasattr (threading .current_thread (), '__decimal_context__' ):
457
- del threading .current_thread ().__decimal_context__
458
-
459
- def setcontext (context ):
460
- """Set this thread's context to context."""
461
- if context in (DefaultContext , BasicContext , ExtendedContext ):
462
- context = context .copy ()
463
- context .clear_flags ()
464
- threading .current_thread ().__decimal_context__ = context
465
-
466
- def getcontext ():
467
- """Returns this thread's context.
468
-
469
- If this thread does not yet have a context, returns
470
- a new context and sets this thread's context.
471
- New contexts are copies of DefaultContext.
472
- """
473
- try :
474
- return threading .current_thread ().__decimal_context__
475
- except AttributeError :
476
- context = Context ()
477
- threading .current_thread ().__decimal_context__ = context
478
- return context
439
+ import threading
479
440
480
- else :
441
+ local = threading .local ()
442
+ if hasattr (local , '__decimal_context__' ):
443
+ del local .__decimal_context__
481
444
482
- local = threading .local ()
483
- if hasattr (local , '__decimal_context__' ):
484
- del local .__decimal_context__
445
+ def getcontext (_local = local ):
446
+ """Returns this thread's context.
485
447
486
- def getcontext (_local = local ):
487
- """Returns this thread's context.
488
-
489
- If this thread does not yet have a context, returns
490
- a new context and sets this thread's context.
491
- New contexts are copies of DefaultContext.
492
- """
493
- try :
494
- return _local .__decimal_context__
495
- except AttributeError :
496
- context = Context ()
497
- _local .__decimal_context__ = context
498
- return context
499
-
500
- def setcontext (context , _local = local ):
501
- """Set this thread's context to context."""
502
- if context in (DefaultContext , BasicContext , ExtendedContext ):
503
- context = context .copy ()
504
- context .clear_flags ()
448
+ If this thread does not yet have a context, returns
449
+ a new context and sets this thread's context.
450
+ New contexts are copies of DefaultContext.
451
+ """
452
+ try :
453
+ return _local .__decimal_context__
454
+ except AttributeError :
455
+ context = Context ()
505
456
_local .__decimal_context__ = context
457
+ return context
458
+
459
+ def setcontext (context , _local = local ):
460
+ """Set this thread's context to context."""
461
+ if context in (DefaultContext , BasicContext , ExtendedContext ):
462
+ context = context .copy ()
463
+ context .clear_flags ()
464
+ _local .__decimal_context__ = context
506
465
507
- del threading , local # Don't contaminate the namespace
466
+ del threading , local # Don't contaminate the namespace
508
467
509
468
def localcontext (ctx = None ):
510
469
"""Return a context manager for a copy of the supplied context
0 commit comments