From f0745f4a7bdcc2388c199bf1e41ee911adfd150e Mon Sep 17 00:00:00 2001 From: Helmut Merz Date: Thu, 1 Oct 2026 12:03:58 +0200 Subject: [PATCH] util: + Symbol and keywords stuff (with tests) --- scopes/util.py | 17 +++++++++++++++++ tests/test_util.py | 13 +++++++++++++ 2 files changed, 30 insertions(+) create mode 100644 tests/test_util.py diff --git a/scopes/util.py b/scopes/util.py index a3d637c..52f353d 100644 --- a/scopes/util.py +++ b/scopes/util.py @@ -5,6 +5,23 @@ import hashlib from secrets import choice import string +# symbols and keywords + +class Symbol(str): + + def __repr__(self): + return f'' + +class Symbols: + + def __getattr__(self, k): + sym = Symbol(k) + setattr(self, k, sym) + return sym + +keywords = Symbols() + + # random strings, hashes, encodings # for authentication, encryption, and other purposes diff --git a/tests/test_util.py b/tests/test_util.py new file mode 100644 index 0000000..cc2c0f6 --- /dev/null +++ b/tests/test_util.py @@ -0,0 +1,13 @@ +# py-scopes: tests.test_util + +"""Tests for scopes.util package""" + +import pytest + +from scopes.util import keywords as k + +def test_keywords(): + assert k.dummy is k.dummy + assert k.dummy is not k.other + assert getattr(k, "abcd"[-2:]) is k.cd +