diff --git a/CHANGELOG.md b/CHANGELOG.md index 93d89b0fbbf240cb5cc0ad34d89287fb7d1b2510..810021019befed8b716e8703d056e0cb8deb8035 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,5 @@ # v2.24.2 * added DeferredValue +* satella.coding.Context are considered experimental diff --git a/satella/__init__.py b/satella/__init__.py index 6a8e7b4da11b9c323bbecdb40c44e4e213f4945c..6aaf86b1b0f22cbadc02610933c9e9ea90cacf26 100644 --- a/satella/__init__.py +++ b/satella/__init__.py @@ -1 +1 @@ -__version__ = '2.24.2a2' +__version__ = '2.24.2a3' diff --git a/satella/coding/environment.py b/satella/coding/environment.py index a871ac4a2bd128dd75f71820bb5ea98a04108b8d..17e2dd9dfeabb07a8cb9d6ac35ab6fb7955de9b9 100644 --- a/satella/coding/environment.py +++ b/satella/coding/environment.py @@ -2,6 +2,7 @@ from __future__ import annotations import threading import typing as tp +import warnings from satella.coding.typing import V @@ -13,9 +14,12 @@ THEY_HATIN = object() class Context: """ New layer of environment. Can have it's own variables, or can hoist them onto the parent. + + .. warning:: This is considered experimental. I just haven't found out a good use case for it yet. """ def __init__(self, parent: tp.Optional[Context] = None, **variables): + warnings.warn('This is experimental', RuntimeWarning) self.parent = parent self.variables = variables self.bool = None diff --git a/satella/debug/test_environment.py b/tests/test_coding/test_environment.py similarity index 73% rename from satella/debug/test_environment.py rename to tests/test_coding/test_environment.py index 2b1e959af21d37f6e388afaeffff5fa39385ee22..9ecfaacdad34af6522bf4bb263a87f139e913503 100644 --- a/satella/debug/test_environment.py +++ b/tests/test_coding/test_environment.py @@ -1,3 +1,4 @@ +import threading import unittest from satella.coding.environment import Context @@ -12,6 +13,19 @@ class TestEnvs(unittest.TestCase): with Context() as new_ctxt: self.assertEqual(new_ctxt.value, 5) + def test_threads(self): + ctxt = Context.get() + ctxt.value = 2 + with ctxt: + def thread(): + with Context() as new_ctxt: + self.assertEqual(new_ctxt.value, 2) + new_ctxt.value2 = 2 + thr = threading.Thread(target=thread) + thr.start() + thr.join() + self.assertRaises(AttributeError, lambda: ctxt.value2) + def test_push(self): ctxt = Context.get() ctxt.value = 5