Skip to content

Commit

Permalink
Drop Python 3.8 support (#209)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
stefanvanburen authored Oct 28, 2024
1 parent cdc1c29 commit c16dbb7
Show file tree
Hide file tree
Showing 7 changed files with 199 additions and 185 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
strategy:
fail-fast: false
matrix:
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12", "3.13"]
python-version: ["3.9", "3.10", "3.11", "3.12", "3.13"]
steps:
- name: Checkout code
uses: actions/checkout@v4
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/conformance.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
strategy:
fail-fast: false
matrix:
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12", "3.13"]
python-version: ["3.9", "3.10", "3.11", "3.12", "3.13"]
steps:
- name: Checkout code
uses: actions/checkout@v4
Expand Down
336 changes: 177 additions & 159 deletions Pipfile.lock

Large diffs are not rendered by default.

34 changes: 17 additions & 17 deletions protovalidate/internal/constraints.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ def __getitem__(self, name):
return super().__getitem__(name)


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

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

def __init__(self, rules: typing.Optional[message.Message]):
Expand All @@ -259,7 +259,7 @@ def _validate_cel(
self,
ctx: ConstraintContext,
field_name: str,
activation: typing.Dict[str, typing.Any],
activation: dict[str, typing.Any],
*,
for_key: bool = False,
):
Expand All @@ -280,7 +280,7 @@ def _validate_cel(
def add_rule(
self,
env: celpy.Environment,
funcs: typing.Dict[str, celpy.CELFunction],
funcs: dict[str, celpy.CELFunction],
rules: validate_pb2.Constraint,
*,
rule: typing.Optional[celtypes.Value] = None,
Expand Down Expand Up @@ -335,7 +335,7 @@ class FieldConstraintRules(CelConstraintRules):
def __init__(
self,
env: celpy.Environment,
funcs: typing.Dict[str, celpy.CELFunction],
funcs: dict[str, celpy.CELFunction],
field: descriptor.FieldDescriptor,
field_level: validate_pb2.FieldConstraints,
*,
Expand Down Expand Up @@ -395,13 +395,13 @@ def _validate_value(self, ctx: ConstraintContext, field_path: str, val: typing.A
class AnyConstraintRules(FieldConstraintRules):
"""Rules for an Any field."""

_in: typing.List[str] = [] # noqa: RUF012
_not_in: typing.List[str] = [] # noqa: RUF012
_in: list[str] = [] # noqa: RUF012
_not_in: list[str] = [] # noqa: RUF012

def __init__(
self,
env: celpy.Environment,
funcs: typing.Dict[str, celpy.CELFunction],
funcs: dict[str, celpy.CELFunction],
field: descriptor.FieldDescriptor,
field_level: validate_pb2.FieldConstraints,
):
Expand Down Expand Up @@ -437,7 +437,7 @@ class EnumConstraintRules(FieldConstraintRules):
def __init__(
self,
env: celpy.Environment,
funcs: typing.Dict[str, celpy.CELFunction],
funcs: dict[str, celpy.CELFunction],
field: descriptor.FieldDescriptor,
field_level: validate_pb2.FieldConstraints,
*,
Expand Down Expand Up @@ -469,7 +469,7 @@ class RepeatedConstraintRules(FieldConstraintRules):
def __init__(
self,
env: celpy.Environment,
funcs: typing.Dict[str, celpy.CELFunction],
funcs: dict[str, celpy.CELFunction],
field: descriptor.FieldDescriptor,
field_level: validate_pb2.FieldConstraints,
item_rules: typing.Optional[FieldConstraintRules],
Expand Down Expand Up @@ -505,7 +505,7 @@ class MapConstraintRules(FieldConstraintRules):
def __init__(
self,
env: celpy.Environment,
funcs: typing.Dict[str, celpy.CELFunction],
funcs: dict[str, celpy.CELFunction],
field: descriptor.FieldDescriptor,
field_level: validate_pb2.FieldConstraints,
key_rules: typing.Optional[FieldConstraintRules],
Expand Down Expand Up @@ -557,15 +557,15 @@ class ConstraintFactory:
"""Factory for creating and caching constraints."""

_env: celpy.Environment
_funcs: typing.Dict[str, celpy.CELFunction]
_cache: typing.Dict[descriptor.Descriptor, typing.Union[typing.List[ConstraintRules], Exception]]
_funcs: dict[str, celpy.CELFunction]
_cache: dict[descriptor.Descriptor, typing.Union[list[ConstraintRules], Exception]]

def __init__(self, funcs: typing.Dict[str, celpy.CELFunction]):
def __init__(self, funcs: dict[str, celpy.CELFunction]):
self._env = celpy.Environment(runner_class=InterpretedRunner)
self._funcs = funcs
self._cache = {}

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

def _new_constraints(self, desc: descriptor.Descriptor) -> typing.List[ConstraintRules]:
result: typing.List[ConstraintRules] = []
def _new_constraints(self, desc: descriptor.Descriptor) -> list[ConstraintRules]:
result: list[ConstraintRules] = []
constraint: typing.Optional[ConstraintRules] = None
if validate_pb2.message in desc.GetOptions().Extensions:
message_level = desc.GetOptions().Extensions[validate_pb2.message]
Expand Down
2 changes: 1 addition & 1 deletion protovalidate/internal/extra_func.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ def unique(val: celtypes.Value) -> celpy.Result:
return celtypes.BoolType(len(val) == len(set(val)))


def make_extra_funcs(locale: str) -> typing.Dict[str, celpy.CELFunction]:
def make_extra_funcs(locale: str) -> dict[str, celpy.CELFunction]:
string_fmt = string_format.StringFormat(locale)
return {
# Missing standard functions
Expand Down
4 changes: 1 addition & 3 deletions protovalidate/validator.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import typing

from google.protobuf import message

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

def errors(self) -> typing.List[validate_pb2.Violation]:
def errors(self) -> list[validate_pb2.Violation]:
"""
Returns the validation errors as a simple Python list, rather than the
Protobuf-specific collection type used by Violations.
Expand Down
4 changes: 1 addition & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,8 @@ description = "Protocol Buffer Validation for Python"
readme = "README.md"
license = { file = "LICENSE" }
keywords = ["validate", "protobuf", "protocol buffer"]
requires-python = ">=3.8"
requires-python = ">=3.9"
classifiers = [
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
Expand All @@ -31,7 +30,6 @@ Issues = "https://github.com/bufbuild/protovalidate-python/issues"
source = "vcs"

[tool.ruff]
target-version = "py38"
line-length = 120
lint.select = [
"A",
Expand Down

0 comments on commit c16dbb7

Please sign in to comment.