Skip to content

Commit 20d1353

Browse files
committed
Rename SerdeScope to Scope
1 parent 9693e13 commit 20d1353

File tree

4 files changed

+17
-17
lines changed

4 files changed

+17
-17
lines changed

serde/core.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
from .numpy import is_numpy_available, is_numpy_type
4141

4242
__all__ = [
43-
"SerdeScope",
43+
"Scope",
4444
"gen",
4545
"add_func",
4646
"Func",
@@ -78,7 +78,7 @@ def init(debug: bool = False) -> None:
7878

7979

8080
@dataclass
81-
class SerdeScope:
81+
class Scope:
8282
"""
8383
Container to store types and functions used in code generation context.
8484
"""
@@ -174,12 +174,12 @@ def gen(
174174

175175

176176
def add_func(
177-
serde_scope: SerdeScope, func_name: str, func_code: str, globals: Dict[str, Any]
177+
serde_scope: Scope, func_name: str, func_code: str, globals: Dict[str, Any]
178178
) -> None:
179179
"""
180-
Generate a function and add it to a SerdeScope's `funcs` dictionary.
180+
Generate a function and add it to a Scope's `funcs` dictionary.
181181
182-
* `serde_scope`: the SerdeScope instance to modify
182+
* `serde_scope`: the Scope instance to modify
183183
* `func_name`: the name of the function
184184
* `func_code`: the source code of the function
185185
* `globals`: global variables that should be accessible to the generated function
@@ -198,7 +198,7 @@ def is_instance(obj: Any, typ: Type[Any]) -> bool:
198198
Subscripted Generics e.g. `List[int]`.
199199
"""
200200
if dataclasses.is_dataclass(typ):
201-
serde_scope: Optional[SerdeScope] = getattr(typ, SERDE_SCOPE, None)
201+
serde_scope: Optional[Scope] = getattr(typ, SERDE_SCOPE, None)
202202
if serde_scope:
203203
try:
204204
serde_scope.funcs[TYPE_CHECK](obj)

serde/de.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@
6464
DefaultTagging,
6565
Field,
6666
NoCheck,
67-
SerdeScope,
67+
Scope,
6868
Tagging,
6969
TypeCheck,
7070
add_func,
@@ -214,9 +214,9 @@ def wrap(cls: Type[T]) -> Type[T]:
214214
# Create a scope storage used by serde.
215215
# Each class should get own scope. Child classes can not share scope with parent class.
216216
# That's why we need the "scope.cls is not cls" check.
217-
scope: Optional[SerdeScope] = getattr(cls, SERDE_SCOPE, None)
217+
scope: Optional[Scope] = getattr(cls, SERDE_SCOPE, None)
218218
if scope is None or scope.cls is not cls:
219-
scope = SerdeScope(cls, reuse_instances_default=reuse_instances_default)
219+
scope = Scope(cls, reuse_instances_default=reuse_instances_default)
220220
setattr(cls, SERDE_SCOPE, scope)
221221

222222
# Set some globals for all generated functions
@@ -331,7 +331,7 @@ def is_dataclass_without_de(cls: Type[Any]) -> bool:
331331
return False
332332
if not hasattr(cls, SERDE_SCOPE):
333333
return True
334-
scope: Optional[SerdeScope] = getattr(cls, SERDE_SCOPE)
334+
scope: Optional[Scope] = getattr(cls, SERDE_SCOPE)
335335
return FROM_DICT not in scope.funcs
336336

337337

@@ -362,7 +362,7 @@ def from_obj(c: Type[T], o: Any, named: bool, reuse_instances: bool) -> T:
362362
"""
363363

364364
def deserializable_to_obj(cls):
365-
serde_scope: SerdeScope = getattr(cls, SERDE_SCOPE)
365+
serde_scope: Scope = getattr(cls, SERDE_SCOPE)
366366
func_name = FROM_DICT if named else FROM_ITER
367367
res = serde_scope.funcs[func_name](
368368
cls, maybe_generic=maybe_generic, data=o, reuse_instances=reuse_instances

serde/inspect.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
from typing import Any
2121
from typing_extensions import Type
2222

23-
from .core import SERDE_SCOPE, init, logger
23+
from .core import SERDE_SCOPE, Scope, init, logger
2424

2525
init(True)
2626

serde/se.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@
5858
DefaultTagging,
5959
Field,
6060
NoCheck,
61-
SerdeScope,
61+
Scope,
6262
Tagging,
6363
TypeCheck,
6464
add_func,
@@ -195,9 +195,9 @@ def wrap(cls: Type[T]) -> Type[T]:
195195
# Create a scope storage used by serde.
196196
# Each class should get own scope. Child classes can not share scope with parent class.
197197
# That's why we need the "scope.cls is not cls" check.
198-
scope: Optional[SerdeScope] = getattr(cls, SERDE_SCOPE, None)
198+
scope: Optional[Scope] = getattr(cls, SERDE_SCOPE, None)
199199
if scope is None or scope.cls is not cls:
200-
scope = SerdeScope(
200+
scope = Scope(
201201
cls,
202202
reuse_instances_default=reuse_instances_default,
203203
convert_sets_default=convert_sets_default,
@@ -303,15 +303,15 @@ def is_dataclass_without_se(cls: Type[Any]) -> bool:
303303
return False
304304
if not hasattr(cls, SERDE_SCOPE):
305305
return True
306-
scope: Optional[SerdeScope] = getattr(cls, SERDE_SCOPE)
306+
scope: Optional[Scope] = getattr(cls, SERDE_SCOPE)
307307
return TO_DICT not in scope.funcs
308308

309309

310310
def to_obj(
311311
o, named: bool, reuse_instances: bool, convert_sets: bool, c: Optional[Type[Any]] = None
312312
):
313313
def serializable_to_obj(object):
314-
serde_scope: SerdeScope = getattr(object, SERDE_SCOPE)
314+
serde_scope: Scope = getattr(object, SERDE_SCOPE)
315315
func_name = TO_DICT if named else TO_ITER
316316
return serde_scope.funcs[func_name](
317317
object, reuse_instances=reuse_instances, convert_sets=convert_sets

0 commit comments

Comments
 (0)