diff --git a/mashumaro/core/meta/code/builder.py b/mashumaro/core/meta/code/builder.py index 655cde76..3dcf9d89 100644 --- a/mashumaro/core/meta/code/builder.py +++ b/mashumaro/core/meta/code/builder.py @@ -53,7 +53,12 @@ substitute_type_params, type_name, ) -from mashumaro.core.meta.types.common import FieldContext, NoneType, ValueSpec, clean_id +from mashumaro.core.meta.types.common import ( + FieldContext, + NoneType, + ValueSpec, + clean_id, +) from mashumaro.core.meta.types.pack import PackerRegistry from mashumaro.core.meta.types.unpack import ( SubtypeUnpackerBuilder, diff --git a/mashumaro/core/meta/helpers.py b/mashumaro/core/meta/helpers.py index e556c3aa..38f3555b 100644 --- a/mashumaro/core/meta/helpers.py +++ b/mashumaro/core/meta/helpers.py @@ -387,9 +387,11 @@ def is_literal(typ: Type) -> bool: return type(typ) is typing._LiteralGenericAlias # type: ignore return False + def is_local_type(typ: Type) -> bool: return "" in getattr(typ, "__qualname__", "") + def not_none_type_arg( type_args: Tuple[Type, ...], resolved_type_params: Optional[Dict[Type, Type]] = None, diff --git a/mashumaro/core/meta/types/common.py b/mashumaro/core/meta/types/common.py index bf6626d2..04221222 100644 --- a/mashumaro/core/meta/types/common.py +++ b/mashumaro/core/meta/types/common.py @@ -303,8 +303,10 @@ def expr_or_maybe_none(spec: ValueSpec, new_expr: Expression) -> Expression: def random_hex() -> str: return str(uuid.uuid4().hex) + _PY_VALID_ID_RE = re.compile(r"\W|^(?=\d)") + def clean_id(value: str) -> str: if not value: return "_"