util: + Symbol and keywords stuff (with tests)

This commit is contained in:
Helmut Merz 2026-10-01 12:03:58 +02:00
parent afe858fc9f
commit f0745f4a7b
2 changed files with 30 additions and 0 deletions

View file

@ -5,6 +5,23 @@ import hashlib
from secrets import choice from secrets import choice
import string import string
# symbols and keywords
class Symbol(str):
def __repr__(self):
return f'<Symbol "{self}">'
class Symbols:
def __getattr__(self, k):
sym = Symbol(k)
setattr(self, k, sym)
return sym
keywords = Symbols()
# random strings, hashes, encodings # random strings, hashes, encodings
# for authentication, encryption, and other purposes # for authentication, encryption, and other purposes

13
tests/test_util.py Normal file
View file

@ -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