Skip to content

Bump Python language version support #203

New issue

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

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

Already on GitHub? Sign in to your account

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
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
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"]
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"]
python-version: ["3.9", "3.10", "3.11", "3.12", "3.13"]
steps:
- name: Checkout code
uses: actions/checkout@v4
Expand Down
5 changes: 1 addition & 4 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@ on:
release:
types: [published]

env:
PYTHON_VERSION: '3.7.17'

jobs:
build:
name: Build package
Expand All @@ -15,7 +12,7 @@ jobs:
name: release
strategy:
matrix:
python-version: [ "3.11" ]
python-version: [ "3.13" ]
steps:
- name: Checkout source
uses: actions/checkout@v4
Expand Down
2 changes: 1 addition & 1 deletion Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@ exceptiongroup = "*"
tomli = "*"

[requires]
python_version = "3.8"
python_version = "3.9"
356 changes: 192 additions & 164 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: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ 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",
"License :: OSI Approved :: Apache Software License",
Expand All @@ -26,7 +26,7 @@ Issues = "https://github.com/bufbuild/protovalidate-python/issues"
source = "vcs"

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