Skip to content

Commit

Permalink
Use TypeVar for Schema.schema type
Browse files Browse the repository at this point in the history
  • Loading branch information
cdce8p committed Jun 26, 2024
1 parent 66df7be commit c38f8f9
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions voluptuous/schema_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,8 +162,10 @@ def Extra(_) -> None:
]
# fmt: on

_SchemableT = typing.TypeVar("_SchemableT", bound=Schemable)

class Schema(object):

class Schema(typing.Generic[_SchemableT]):
"""A validation schema.
The schema is a Python tree-like structure where nodes are pattern
Expand Down Expand Up @@ -192,7 +194,7 @@ class Schema(object):
}

def __init__(
self, schema: Schemable, required: bool = False, extra: int = PREVENT_EXTRA
self, schema: _SchemableT, required: bool = False, extra: int = PREVENT_EXTRA
) -> None:
"""Create a new Schema.
Expand Down Expand Up @@ -812,7 +814,7 @@ def key_literal(key):
result[key] = value

# recompile and send old object
result_cls = type(self)
result_cls = typing.cast("type[Schema[dict]]", type(self))
result_required = required if required is not None else self.required
result_extra = extra if extra is not None else self.extra
return result_cls(result, required=result_required, extra=result_extra)
Expand Down

0 comments on commit c38f8f9

Please sign in to comment.