Skip to content

Commit dd967d6

Browse files
Run uvx pyupgrade --py39-plus protovalidate/**.py tests/**.py
1 parent 6237e5c commit dd967d6

File tree

3 files changed

+19
-19
lines changed

3 files changed

+19
-19
lines changed

protovalidate/internal/constraints.py

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ def __getitem__(self, name):
8686
return super().__getitem__(name)
8787

8888

89-
def _msg_to_cel(msg: message.Message) -> typing.Dict[str, celtypes.Value]:
89+
def _msg_to_cel(msg: message.Message) -> dict[str, celtypes.Value]:
9090
ctor = _MSG_TYPE_URL_TO_CTOR.get(msg.DESCRIPTOR.full_name)
9191
if ctor is not None:
9292
return ctor(msg)
@@ -247,7 +247,7 @@ def validate(self, ctx: ConstraintContext, message: message.Message): # noqa: A
247247
class CelConstraintRules(ConstraintRules):
248248
"""A constraint that has rules written in CEL."""
249249

250-
_runners: typing.List[typing.Tuple[celpy.Runner, validate_pb2.Constraint, typing.Optional[celtypes.Value]]]
250+
_runners: list[tuple[celpy.Runner, validate_pb2.Constraint, typing.Optional[celtypes.Value]]]
251251
_rules_cel: celtypes.Value = None
252252

253253
def __init__(self, rules: typing.Optional[message.Message]):
@@ -259,7 +259,7 @@ def _validate_cel(
259259
self,
260260
ctx: ConstraintContext,
261261
field_name: str,
262-
activation: typing.Dict[str, typing.Any],
262+
activation: dict[str, typing.Any],
263263
*,
264264
for_key: bool = False,
265265
):
@@ -280,7 +280,7 @@ def _validate_cel(
280280
def add_rule(
281281
self,
282282
env: celpy.Environment,
283-
funcs: typing.Dict[str, celpy.CELFunction],
283+
funcs: dict[str, celpy.CELFunction],
284284
rules: validate_pb2.Constraint,
285285
*,
286286
rule: typing.Optional[celtypes.Value] = None,
@@ -335,7 +335,7 @@ class FieldConstraintRules(CelConstraintRules):
335335
def __init__(
336336
self,
337337
env: celpy.Environment,
338-
funcs: typing.Dict[str, celpy.CELFunction],
338+
funcs: dict[str, celpy.CELFunction],
339339
field: descriptor.FieldDescriptor,
340340
field_level: validate_pb2.FieldConstraints,
341341
*,
@@ -395,13 +395,13 @@ def _validate_value(self, ctx: ConstraintContext, field_path: str, val: typing.A
395395
class AnyConstraintRules(FieldConstraintRules):
396396
"""Rules for an Any field."""
397397

398-
_in: typing.List[str] = [] # noqa: RUF012
399-
_not_in: typing.List[str] = [] # noqa: RUF012
398+
_in: list[str] = [] # noqa: RUF012
399+
_not_in: list[str] = [] # noqa: RUF012
400400

401401
def __init__(
402402
self,
403403
env: celpy.Environment,
404-
funcs: typing.Dict[str, celpy.CELFunction],
404+
funcs: dict[str, celpy.CELFunction],
405405
field: descriptor.FieldDescriptor,
406406
field_level: validate_pb2.FieldConstraints,
407407
):
@@ -437,7 +437,7 @@ class EnumConstraintRules(FieldConstraintRules):
437437
def __init__(
438438
self,
439439
env: celpy.Environment,
440-
funcs: typing.Dict[str, celpy.CELFunction],
440+
funcs: dict[str, celpy.CELFunction],
441441
field: descriptor.FieldDescriptor,
442442
field_level: validate_pb2.FieldConstraints,
443443
*,
@@ -469,7 +469,7 @@ class RepeatedConstraintRules(FieldConstraintRules):
469469
def __init__(
470470
self,
471471
env: celpy.Environment,
472-
funcs: typing.Dict[str, celpy.CELFunction],
472+
funcs: dict[str, celpy.CELFunction],
473473
field: descriptor.FieldDescriptor,
474474
field_level: validate_pb2.FieldConstraints,
475475
item_rules: typing.Optional[FieldConstraintRules],
@@ -505,7 +505,7 @@ class MapConstraintRules(FieldConstraintRules):
505505
def __init__(
506506
self,
507507
env: celpy.Environment,
508-
funcs: typing.Dict[str, celpy.CELFunction],
508+
funcs: dict[str, celpy.CELFunction],
509509
field: descriptor.FieldDescriptor,
510510
field_level: validate_pb2.FieldConstraints,
511511
key_rules: typing.Optional[FieldConstraintRules],
@@ -557,15 +557,15 @@ class ConstraintFactory:
557557
"""Factory for creating and caching constraints."""
558558

559559
_env: celpy.Environment
560-
_funcs: typing.Dict[str, celpy.CELFunction]
561-
_cache: typing.Dict[descriptor.Descriptor, typing.Union[typing.List[ConstraintRules], Exception]]
560+
_funcs: dict[str, celpy.CELFunction]
561+
_cache: dict[descriptor.Descriptor, typing.Union[list[ConstraintRules], Exception]]
562562

563-
def __init__(self, funcs: typing.Dict[str, celpy.CELFunction]):
563+
def __init__(self, funcs: dict[str, celpy.CELFunction]):
564564
self._env = celpy.Environment(runner_class=InterpretedRunner)
565565
self._funcs = funcs
566566
self._cache = {}
567567

568-
def get(self, descriptor: descriptor.Descriptor) -> typing.List[ConstraintRules]:
568+
def get(self, descriptor: descriptor.Descriptor) -> list[ConstraintRules]:
569569
if descriptor not in self._cache:
570570
try:
571571
self._cache[descriptor] = self._new_constraints(descriptor)
@@ -726,8 +726,8 @@ def _new_field_constraint(
726726
item_rule = self._new_scalar_field_constraint(field, rules.repeated.items)
727727
return RepeatedConstraintRules(self._env, self._funcs, field, rules, item_rule)
728728

729-
def _new_constraints(self, desc: descriptor.Descriptor) -> typing.List[ConstraintRules]:
730-
result: typing.List[ConstraintRules] = []
729+
def _new_constraints(self, desc: descriptor.Descriptor) -> list[ConstraintRules]:
730+
result: list[ConstraintRules] = []
731731
constraint: typing.Optional[ConstraintRules] = None
732732
if validate_pb2.message in desc.GetOptions().Extensions:
733733
message_level = desc.GetOptions().Extensions[validate_pb2.message]

protovalidate/internal/extra_func.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ def unique(val: celtypes.Value) -> celpy.Result:
226226
return celtypes.BoolType(len(val) == len(set(val)))
227227

228228

229-
def make_extra_funcs(locale: str) -> typing.Dict[str, celpy.CELFunction]:
229+
def make_extra_funcs(locale: str) -> dict[str, celpy.CELFunction]:
230230
string_fmt = string_format.StringFormat(locale)
231231
return {
232232
# Missing standard functions

protovalidate/validator.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ def __init__(self, msg: str, violations: validate_pb2.Violations):
100100
super().__init__(msg)
101101
self.violations = violations
102102

103-
def errors(self) -> typing.List[validate_pb2.Violation]:
103+
def errors(self) -> list[validate_pb2.Violation]:
104104
"""
105105
Returns the validation errors as a simple Python list, rather than the
106106
Protobuf-specific collection type used by Violations.

0 commit comments

Comments
 (0)