Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Use TypeVar for Schema.schema type #520

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading