Skip to content

Commit 9e83b45

Browse files
First pass at types update
The rest is just string_format, which does not appear to be flexed by conformance.
1 parent 59df391 commit 9e83b45

File tree

3 files changed

+10
-10
lines changed

3 files changed

+10
-10
lines changed

protovalidate/internal/constraints.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,14 @@ def make_duration(msg: message.Message) -> celtypes.DurationType:
3636

3737

3838
def make_timestamp(msg: message.Message) -> celtypes.TimestampType:
39-
return make_duration(msg) + celtypes.TimestampType(1970, 1, 1)
39+
return celtypes.TimestampType(1970, 1, 1) + make_duration(msg)
4040

4141

4242
def unwrap(msg: message.Message) -> celtypes.Value:
4343
return _field_to_cel(msg, msg.DESCRIPTOR.fields_by_name["value"])
4444

4545

46-
_MSG_TYPE_URL_TO_CTOR = {
46+
_MSG_TYPE_URL_TO_CTOR: dict[str, typing.Callable[..., celtypes.Value]] = {
4747
"google.protobuf.Duration": make_duration,
4848
"google.protobuf.Timestamp": make_timestamp,
4949
"google.protobuf.StringValue": unwrap,
@@ -89,7 +89,7 @@ def _msg_to_cel(msg: message.Message) -> celtypes.Value:
8989
return MessageType(msg)
9090

9191

92-
_TYPE_TO_CTOR = {
92+
_TYPE_TO_CTOR: dict[str, typing.Callable[..., celtypes.Value]] = {
9393
descriptor.FieldDescriptor.TYPE_MESSAGE: _msg_to_cel,
9494
descriptor.FieldDescriptor.TYPE_GROUP: _msg_to_cel,
9595
descriptor.FieldDescriptor.TYPE_ENUM: celtypes.IntType,

protovalidate/internal/extra_func.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -143,11 +143,11 @@ def is_ip_prefix(val: celtypes.Value, *args) -> celpy.Result:
143143
raise celpy.CELEvalError(msg)
144144
try:
145145
if version is None:
146-
ip_network(val, strict=strict)
146+
ip_network(val, strict=bool(strict))
147147
elif version == 4:
148-
IPv4Network(val, strict=strict)
148+
IPv4Network(val, strict=bool(strict))
149149
elif version == 6:
150-
IPv6Network(val, strict=strict)
150+
IPv6Network(val, strict=bool(strict))
151151
else:
152152
msg = "invalid argument, expected 4 or 6"
153153
raise celpy.CELEvalError(msg)
@@ -164,7 +164,7 @@ def is_email(string: celtypes.Value) -> celpy.Result:
164164

165165

166166
def is_uri(string: celtypes.Value) -> celpy.Result:
167-
url = urlparse.urlparse(string)
167+
url = urlparse.urlparse(str(string))
168168
# urlparse correctly reads the scheme from URNs but parses everything
169169
# after (except the query string) as the path.
170170
if url.scheme == "urn":
@@ -182,7 +182,7 @@ def is_uri(string: celtypes.Value) -> celpy.Result:
182182

183183

184184
def is_uri_ref(string: celtypes.Value) -> celpy.Result:
185-
url = urlparse.urlparse(string)
185+
url = urlparse.urlparse(str(string))
186186
if not all([url.scheme, url.path]) and url.fragment:
187187
return celtypes.BoolType(False)
188188
return celtypes.BoolType(True)

protovalidate/internal/string_format.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,9 @@ def __init__(self, locale: str):
4242

4343
def format(self, fmt: celtypes.Value, args: celtypes.Value) -> celpy.Result:
4444
if not isinstance(fmt, celtypes.StringType):
45-
return celpy.native_to_cel(celpy.new_error("format() requires a string as the first argument"))
45+
return celpy.CELEvalError("format() requires a string as the first argument")
4646
if not isinstance(args, celtypes.ListType):
47-
return celpy.native_to_cel(celpy.new_error("format() requires a list as the second argument"))
47+
return celpy.CELEvalError("format() requires a list as the second argument")
4848
# printf style formatting
4949
i = 0
5050
j = 0

0 commit comments

Comments
 (0)