Skip to content

Commit c16dbb7

Browse files
Drop Python 3.8 support (#209)
Python 3.8 is [EOL as of 2024-10-07][1]. This patch: * Drops support for Python 3.8 * Upgrades our syntax to 3.9 * Re-locks our deps to 3.9 Assuming we do this, our next release should be `v0.6`. Fixes #202. [1]: https://devguide.python.org/versions/#unsupported-versions
1 parent cdc1c29 commit c16dbb7

File tree

7 files changed

+199
-185
lines changed

7 files changed

+199
-185
lines changed

.github/workflows/ci.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ jobs:
1717
strategy:
1818
fail-fast: false
1919
matrix:
20-
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12", "3.13"]
20+
python-version: ["3.9", "3.10", "3.11", "3.12", "3.13"]
2121
steps:
2222
- name: Checkout code
2323
uses: actions/checkout@v4

.github/workflows/conformance.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ jobs:
1717
strategy:
1818
fail-fast: false
1919
matrix:
20-
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12", "3.13"]
20+
python-version: ["3.9", "3.10", "3.11", "3.12", "3.13"]
2121
steps:
2222
- name: Checkout code
2323
uses: actions/checkout@v4

Pipfile.lock

Lines changed: 177 additions & 159 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

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 & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
import typing
16-
1715
from google.protobuf import message
1816

1917
from buf.validate import validate_pb2 # type: ignore
@@ -100,7 +98,7 @@ def __init__(self, msg: str, violations: validate_pb2.Violations):
10098
super().__init__(msg)
10199
self.violations = violations
102100

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

pyproject.toml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,8 @@ description = "Protocol Buffer Validation for Python"
88
readme = "README.md"
99
license = { file = "LICENSE" }
1010
keywords = ["validate", "protobuf", "protocol buffer"]
11-
requires-python = ">=3.8"
11+
requires-python = ">=3.9"
1212
classifiers = [
13-
"Programming Language :: Python :: 3.8",
1413
"Programming Language :: Python :: 3.9",
1514
"Programming Language :: Python :: 3.10",
1615
"Programming Language :: Python :: 3.11",
@@ -31,7 +30,6 @@ Issues = "https://github.com/bufbuild/protovalidate-python/issues"
3130
source = "vcs"
3231

3332
[tool.ruff]
34-
target-version = "py38"
3533
line-length = 120
3634
lint.select = [
3735
"A",

0 commit comments

Comments
 (0)