Skip to content
Open
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
8 changes: 4 additions & 4 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ repos:
- id: mypy
files: ^(src/cloudevents/|tests/)
exclude: ^(src/cloudevents/v1/)
types: [ python ]
args: [
"--config-file=pyproject.toml",
]
types: [python]
args: ["--config-file=pyproject.toml"]
additional_dependencies:
- types-python-dateutil>=2.9.0.20241003
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ dependencies = [
requires = ["hatchling"]
build-backend = "hatchling.build"

[tool.uv]
dev-dependencies = [
[dependency-groups]
dev = [
"pytest>=8.3.3",
"mypy>=1.11.2",
"isort>=5.13.2",
Expand Down
17 changes: 9 additions & 8 deletions src/cloudevents/core/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,8 @@
# License for the specific language governing permissions and limitations
# under the License.


from datetime import datetime
from typing import Any, Optional, Protocol, Union
from typing import Any, Protocol


class BaseCloudEvent(Protocol):
Expand All @@ -27,7 +26,9 @@ class BaseCloudEvent(Protocol):
"""

def __init__(
self, attributes: dict[str, Any], data: Optional[Union[dict, str, bytes]] = None
self,
attributes: dict[str, Any],
data: dict[str, Any] | str | bytes | None = None,
) -> None:
"""
Create a new CloudEvent instance.
Expand Down Expand Up @@ -72,31 +73,31 @@ def get_specversion(self) -> str:
"""
...

def get_datacontenttype(self) -> Optional[str]:
def get_datacontenttype(self) -> str | None:
"""
Retrieve the datacontenttype of the event.

:return: The datacontenttype of the event.
"""
...

def get_dataschema(self) -> Optional[str]:
def get_dataschema(self) -> str | None:
"""
Retrieve the dataschema of the event.

:return: The dataschema of the event.
"""
...

def get_subject(self) -> Optional[str]:
def get_subject(self) -> str | None:
"""
Retrieve the subject of the event.

:return: The subject of the event.
"""
...

def get_time(self) -> Optional[datetime]:
def get_time(self) -> datetime | None:
"""
Retrieve the time of the event.

Expand All @@ -113,7 +114,7 @@ def get_extension(self, extension_name: str) -> Any:
"""
...

def get_data(self) -> Optional[Union[dict, str, bytes]]:
def get_data(self) -> dict[str, Any] | str | bytes | None:
"""
Retrieve data of the event.

Expand Down
31 changes: 31 additions & 0 deletions src/cloudevents/core/bindings/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Copyright 2018-Present The CloudEvents Authors
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.

from cloudevents.core.bindings.http import (
HTTPMessage,
from_binary,
from_http,
from_structured,
to_binary,
to_structured,
)

__all__ = [
"HTTPMessage",
"to_binary",
"from_binary",
"to_structured",
"from_structured",
"from_http",
]
Loading
Loading