Skip to content

Commit 7db90a3

Browse files
committed
Use monic_bind and monic_bind_module instead of register and register_module
1 parent ea73009 commit 7db90a3

File tree

5 files changed

+72
-59
lines changed

5 files changed

+72
-59
lines changed

examples/http/main.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
ExpressionsContext,
1414
ExpressionsParser,
1515
ExpressionsInterpreter,
16-
register,
16+
monic_bind,
1717
)
1818

1919

@@ -25,7 +25,7 @@ class ComputeInput(BaseModel):
2525
timeout: float = 10.0
2626

2727

28-
@register
28+
@monic_bind
2929
def say_hello(name: str) -> str:
3030
return f"Hello, {name}!"
3131

monic/expressions/__init__.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,12 @@
1111
)
1212
from monic.expressions.interpreter import ExpressionsInterpreter
1313
from monic.expressions.parser import ExpressionsParser
14-
from monic.expressions.registry import register, register_module
14+
from monic.expressions.registry import (
15+
monic_bind,
16+
monic_bind_module,
17+
register,
18+
register_module,
19+
)
1520

1621

1722
__all__ = [
@@ -23,6 +28,8 @@
2328
"SecurityError",
2429
"UnsupportedUnpackingError",
2530
# Registry
31+
"monic_bind",
32+
"monic_bind_module",
2633
"register",
2734
"register_module",
2835
]

monic/expressions/registry.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,3 +285,9 @@ def get(self, name: str) -> t.Any:
285285

286286
# Function for registering modules
287287
register_module = registry.register_module
288+
289+
# Decorator for binding objects to the registry
290+
monic_bind = registry.register
291+
292+
# Function for binding modules to the registry
293+
monic_bind_module = registry.register_module

tests/expressions/test_interpreter_coverage1.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
ExpressionsInterpreter,
1414
UnsupportedUnpackingError,
1515
SecurityError,
16-
register,
16+
monic_bind,
1717
)
1818
from monic.expressions.registry import registry
1919

@@ -38,7 +38,7 @@ def test_complex_method_handling():
3838
interpreter = ExpressionsInterpreter()
3939

4040
# Test property descriptor
41-
@register("test.TestClass")
41+
@monic_bind("test.TestClass")
4242
class TestClass:
4343
def __init__(self):
4444
self._value = 0
@@ -339,22 +339,22 @@ def test_registry_error_paths():
339339
ValueError, match="is already registered as a non-namespace"
340340
):
341341

342-
@register("test")
342+
@monic_bind("test")
343343
def test_func():
344344
return 42 # pragma: no cover
345345

346-
@register("test.func")
346+
@monic_bind("test.func")
347347
def test_func2():
348348
return 43 # pragma: no cover
349349

350350
# Test duplicate registration
351-
@register("math.add")
351+
@monic_bind("math.add")
352352
def add1():
353353
return 42 # pragma: no cover
354354

355355
with pytest.raises(ValueError, match="already registered"):
356356

357-
@register("math.add")
357+
@monic_bind("math.add")
358358
def add2():
359359
return 43 # pragma: no cover
360360

tests/expressions/test_interpreter_registry.py

Lines changed: 50 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111
from monic.expressions import (
1212
ExpressionsParser,
1313
ExpressionsInterpreter,
14-
register,
15-
register_module,
14+
monic_bind,
15+
monic_bind_module,
1616
)
1717
from monic.expressions.registry import registry, NamespaceProxy
1818

@@ -27,12 +27,12 @@ def reset_registry():
2727
def test_registered_function():
2828
"""Test using registered functions."""
2929

30-
@register
30+
@monic_bind
3131
def custom_add(x, y): # pylint: disable=unused-variable
3232
"""Custom addition function."""
3333
return x + y
3434

35-
@register("multiply")
35+
@monic_bind("multiply")
3636
def custom_multiply(x, y): # pylint: disable=unused-variable
3737
"""Custom multiplication function."""
3838
return x * y
@@ -52,7 +52,7 @@ def custom_multiply(x, y): # pylint: disable=unused-variable
5252
def test_registered_class():
5353
"""Test using registered class."""
5454

55-
@register
55+
@monic_bind
5656
class Point: # pylint: disable=unused-variable
5757
"""A simple 2D point class."""
5858

@@ -77,7 +77,7 @@ def distance_from_origin(self):
7777
def test_register_without_name():
7878
"""Test registering an object without explicit name."""
7979

80-
@register
80+
@monic_bind
8181
def test_func(): # pylint: disable=unused-variable
8282
return 42
8383

@@ -92,7 +92,7 @@ def test_func(): # pylint: disable=unused-variable
9292
def test_register_with_name():
9393
"""Test registering an object with explicit name."""
9494

95-
@register("answer")
95+
@monic_bind("answer")
9696
def get_answer(): # pylint: disable=unused-variable
9797
return 42
9898

@@ -107,15 +107,15 @@ def get_answer(): # pylint: disable=unused-variable
107107
def test_register_with_nested_name():
108108
"""Test registering objects with nested names."""
109109

110-
@register("math.functions.add")
110+
@monic_bind("math.functions.add")
111111
def add(x, y): # pylint: disable=unused-variable
112112
return x + y
113113

114-
@register("math.functions.multiply")
114+
@monic_bind("math.functions.multiply")
115115
def multiply(x, y): # pylint: disable=unused-variable
116116
return x * y
117117

118-
@register("math.constants")
118+
@monic_bind("math.constants")
119119
class MathConstants: # pylint: disable=unused-variable
120120
PI = 3.14159
121121
E = 2.71828
@@ -139,14 +139,14 @@ class MathConstants: # pylint: disable=unused-variable
139139
def test_register_nested_name_conflict():
140140
"""Test that registering conflicting nested names raises an error."""
141141

142-
@register("math.functions.add")
142+
@monic_bind("math.functions.add")
143143
def add1(x, y): # pylint: disable=unused-variable
144144
return x + y # pragma: no cover
145145

146146
# Try to register another function with the same nested name
147147
with pytest.raises(ValueError) as exc_info:
148148

149-
@register("math.functions.add")
149+
@monic_bind("math.functions.add")
150150
def add2(x, y): # pylint: disable=unused-variable
151151
return x + y # pragma: no cover
152152

@@ -156,14 +156,14 @@ def add2(x, y): # pylint: disable=unused-variable
156156
def test_register_nested_name_non_namespace_conflict():
157157
"""Test conflict between nested name and non-namespace object."""
158158

159-
@register("math")
159+
@monic_bind("math")
160160
def math_func(): # pylint: disable=unused-variable
161161
return 42 # pragma: no cover
162162

163163
# Try to register a function in math.functions namespace
164164
with pytest.raises(ValueError) as exc_info:
165165

166-
@register("math.functions.add")
166+
@monic_bind("math.functions.add")
167167
def add(x, y): # pylint: disable=unused-variable
168168
return x + y # pragma: no cover
169169

@@ -173,11 +173,11 @@ def add(x, y): # pylint: disable=unused-variable
173173
def test_register_both_syntaxes():
174174
"""Test both decorator syntaxes work correctly."""
175175

176-
@register
176+
@monic_bind
177177
def func1(): # pylint: disable=unused-variable
178178
return 1
179179

180-
@register()
180+
@monic_bind()
181181
def func2(): # pylint: disable=unused-variable
182182
return 2
183183

@@ -196,11 +196,11 @@ def func2(): # pylint: disable=unused-variable
196196
def test_register_class_both_syntaxes():
197197
"""Test both decorator syntaxes work correctly with classes."""
198198

199-
@register
199+
@monic_bind
200200
class Class1: # pylint: disable=unused-variable
201201
value = 1
202202

203-
@register()
203+
@monic_bind()
204204
class Class2: # pylint: disable=unused-variable
205205
value = 2
206206

@@ -218,10 +218,10 @@ class Class2: # pylint: disable=unused-variable
218218
assert interpreter.get_name_value("result2") == 2
219219

220220

221-
def test_register_module():
221+
def test_bind_module():
222222
"""Test registering and using a module."""
223-
# Register math module
224-
register_module("math")
223+
# Bind math module
224+
monic_bind_module("math")
225225

226226
code = """
227227
result1 = math.sqrt(16)
@@ -237,10 +237,10 @@ def test_register_module():
237237
)
238238

239239

240-
def test_register_module_with_alias():
240+
def test_bind_module_with_alias():
241241
"""Test registering a module with an alias."""
242-
# Register random module with alias
243-
register_module("random", alias="rand")
242+
# Bind random module with alias
243+
monic_bind_module("random", alias="rand")
244244

245245
code = """
246246
rand.seed(42) # For reproducibility
@@ -255,10 +255,10 @@ def test_register_module_with_alias():
255255
assert 1 <= result <= 10
256256

257257

258-
def test_register_module_submodule():
258+
def test_bind_module_submodule():
259259
"""Test registering a module with submodules."""
260-
# Register collections.abc module
261-
register_module("collections.abc", alias="collabc")
260+
# Bind collections.abc module
261+
monic_bind_module("collections.abc", alias="collabc")
262262

263263
code = """
264264
is_sequence = collabc.Sequence
@@ -272,11 +272,11 @@ def test_register_module_submodule():
272272
assert result is True
273273

274274

275-
def test_register_module_with_nested_name():
275+
def test_bind_module_with_nested_name():
276276
"""Test registering modules with nested names."""
277-
# Register urllib and its parse submodule
278-
register_module("urllib", alias="url")
279-
register_module("urllib.parse", alias="url.parse")
277+
# Bind urllib and its parse submodule
278+
monic_bind_module("urllib", alias="url")
279+
monic_bind_module("urllib.parse", alias="url.parse")
280280

281281
code = """
282282
# Use urllib.parse module
@@ -336,34 +336,34 @@ def test_register_object_without_name():
336336
)
337337

338338

339-
def test_register_module_import_error():
339+
def test_bind_module_import_error():
340340
"""Test that registering a non-existent module raises ImportError."""
341341
with pytest.raises(ImportError) as exc_info:
342-
register_module("non_existent_module")
342+
monic_bind_module("non_existent_module")
343343

344344
assert "Failed to import module 'non_existent_module'" in str(
345345
exc_info.value
346346
)
347347

348348

349-
def test_register_module_duplicate():
349+
def test_bind_module_duplicate():
350350
"""Test that registering the same module twice raises ValueError."""
351-
register_module("math")
351+
monic_bind_module("math")
352352

353353
with pytest.raises(ValueError) as exc_info:
354-
register_module("math")
354+
monic_bind_module("math")
355355

356356
assert "Module 'math' is already registered" in str(exc_info.value)
357357

358358

359359
def test_get_all_with_nested_namespaces():
360360
"""Test that get_all properly handles nested namespaces."""
361361

362-
@register("math.functions.add")
362+
@monic_bind("math.functions.add")
363363
def add(x, y): # pylint: disable=unused-variable
364364
return x + y # pragma: no cover
365365

366-
@register("math.constants")
366+
@monic_bind("math.constants")
367367
class Constants: # pylint: disable=unused-variable
368368
PI = 3.14159
369369

@@ -411,8 +411,8 @@ def test_func():
411411

412412
def test_get_all_with_modules():
413413
"""Test that get_all properly includes registered modules."""
414-
register_module("math", alias="math_alias")
415-
register_module("random")
414+
monic_bind_module("math", alias="math_alias")
415+
monic_bind_module("random")
416416

417417
all_objects = registry.get_all()
418418
assert "math_alias" in all_objects
@@ -475,16 +475,16 @@ def test_get_all_with_mixed_content():
475475
Test that get_all properly handles mixed content
476476
(modules, objects, namespaces).
477477
"""
478-
# Register a module
479-
register_module("math")
478+
# Bind a module
479+
monic_bind_module("math")
480480

481-
# Register a function in a namespace
482-
@register("utils.helper")
481+
# Bind a function in a namespace
482+
@monic_bind("utils.helper")
483483
def helper(): # pylint: disable=unused-variable
484484
pass # pragma: no cover
485485

486-
# Register a direct object
487-
@register
486+
# Bind a direct object
487+
@monic_bind
488488
def direct_func(): # pylint: disable=unused-variable
489489
pass # pragma: no cover
490490

@@ -498,7 +498,7 @@ def direct_func(): # pylint: disable=unused-variable
498498
def test_is_registered_with_string_name():
499499
"""Test is_registered with a string name."""
500500

501-
@register("test.func")
501+
@monic_bind("test.func")
502502
def test_func(): # pylint: disable=unused-variable
503503
pass # pragma: no cover
504504

@@ -509,15 +509,15 @@ def test_func(): # pylint: disable=unused-variable
509509
def test_get_all_with_non_dict_values():
510510
"""Test that get_all properly handles non-dict values."""
511511

512-
@register("test.value")
512+
@monic_bind("test.value")
513513
def test_func(): # pylint: disable=unused-variable
514514
pass # pragma: no cover
515515

516-
@register("direct_value")
516+
@monic_bind("direct_value")
517517
def direct_func(): # pylint: disable=unused-variable
518518
pass # pragma: no cover
519519

520-
register_module("math")
520+
monic_bind_module("math")
521521

522522
all_objects = registry.get_all()
523523
assert callable(all_objects["test"].value) # Nested function

0 commit comments

Comments
 (0)