Skip to content
Merged
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 .pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ ignore-paths=src/s2python/generated/
# avoid hangs.
jobs=1

disable=missing-class-docstring,missing-module-docstring,too-few-public-methods,missing-function-docstring
disable=missing-class-docstring,missing-module-docstring,too-few-public-methods,missing-function-docstring,no-member
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pylint is not smart enough to follow protocols like mypy. Mypy should cover all no-member issues so disable in pylint.


[Format]
max-line-length=120
2 changes: 1 addition & 1 deletion ci/generate_s2.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@


. .venv/bin/activate
datamodel-codegen --input specification/openapi.yml --input-file-type openapi --output src/s2python/generated/gen_s2.py
datamodel-codegen --input specification/openapi.yml --input-file-type openapi --output-model-type pydantic_v2.BaseModel --output src/s2python/generated/gen_s2.py --use-one-literal-as-default
8 changes: 7 additions & 1 deletion dev-requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
#
alabaster==0.7.13
# via sphinx
annotated-types==0.7.0
# via pydantic
argcomplete==3.4.0
# via datamodel-code-generator
astroid==3.2.4
Expand Down Expand Up @@ -121,10 +123,12 @@ pluggy==1.5.0
# tox
pre-commit==3.5.0
# via s2-python (setup.cfg)
pydantic[email]==1.10.17
pydantic[email]==2.8.2
# via
# datamodel-code-generator
# s2-python (setup.cfg)
pydantic-core==2.20.1
# via pydantic
pygments==2.18.0
# via
# sphinx
Expand Down Expand Up @@ -218,10 +222,12 @@ types-pytz==2024.1.0.20240417
# via s2-python (setup.cfg)
typing-extensions==4.12.2
# via
# annotated-types
# astroid
# black
# mypy
# pydantic
# pydantic-core
# pylint
urllib3==2.2.2
# via requests
Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ python_requires >= 3.8, <= 3.12
# new major versions. This works if the required packages follow Semantic Versioning.
# For more information, check out https://semver.org/.
install_requires =
pydantic~=1.10.7
pydantic~=2.8.2
pytz
click

Expand Down
6 changes: 3 additions & 3 deletions src/s2python/common/duration.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@
@catch_and_convert_exceptions
class Duration(GenDuration, S2Message["Duration"]):
def to_timedelta(self) -> timedelta:
return timedelta(milliseconds=self.__root__)
return timedelta(milliseconds=self.root)

@staticmethod
def from_timedelta(duration: timedelta) -> "Duration":
return Duration(__root__=math.ceil(duration.total_seconds() * 1000))
return Duration(root=math.ceil(duration.total_seconds() * 1000))

@staticmethod
def from_milliseconds(milliseconds: int) -> "Duration":
return Duration(__root__=milliseconds)
return Duration(root=milliseconds)
6 changes: 3 additions & 3 deletions src/s2python/common/handshake.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

@catch_and_convert_exceptions
class Handshake(GenHandshake, S2Message["Handshake"]):
class Config(GenHandshake.Config):
validate_assignment = True
model_config = GenHandshake.model_config
model_config["validate_assignment"] = True

message_id: uuid.UUID = GenHandshake.__fields__["message_id"].field_info # type: ignore[assignment]
message_id: uuid.UUID = GenHandshake.model_fields["message_id"] # type: ignore[assignment]
6 changes: 3 additions & 3 deletions src/s2python/common/handshake_response.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

@catch_and_convert_exceptions
class HandshakeResponse(GenHandshakeResponse, S2Message["HandshakeResponse"]):
class Config(GenHandshakeResponse.Config):
validate_assignment = True
model_config = GenHandshakeResponse.model_config
model_config["validate_assignment"] = True

message_id: uuid.UUID = GenHandshakeResponse.__fields__["message_id"].field_info # type: ignore[assignment]
message_id: uuid.UUID = GenHandshakeResponse.model_fields["message_id"] # type: ignore[assignment]
14 changes: 5 additions & 9 deletions src/s2python/common/instruction_status_update.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,9 @@


@catch_and_convert_exceptions
class InstructionStatusUpdate(
GenInstructionStatusUpdate, S2Message["InstructionStatusUpdate"]
):
class Config(GenInstructionStatusUpdate.Config):
validate_assignment = True
class InstructionStatusUpdate(GenInstructionStatusUpdate, S2Message["InstructionStatusUpdate"]):
model_config = GenInstructionStatusUpdate.model_config
model_config["validate_assignment"] = True

message_id: uuid.UUID = GenInstructionStatusUpdate.__fields__["message_id"].field_info # type: ignore[assignment]
instruction_id: uuid.UUID = GenInstructionStatusUpdate.__fields__[
"instruction_id"
].field_info # type: ignore[assignment]
message_id: uuid.UUID = GenInstructionStatusUpdate.model_fields["message_id"] # type: ignore[assignment]
instruction_id: uuid.UUID = GenInstructionStatusUpdate.model_fields["instruction_id"] # type: ignore[assignment]
29 changes: 11 additions & 18 deletions src/s2python/common/number_range.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from typing import Any, Dict
from typing import Any
from typing_extensions import Self

from pydantic import root_validator
from pydantic import model_validator

from s2python.validate_values_mixin import (
S2Message,
Expand All @@ -11,29 +12,21 @@

@catch_and_convert_exceptions
class NumberRange(GenNumberRange, S2Message["NumberRange"]):
class Config(GenNumberRange.Config):
validate_assignment = True
model_config = GenNumberRange.model_config
model_config["validate_assignment"] = True

@root_validator(pre=False)
@classmethod
def validate_start_end_order( # pylint: disable=duplicate-code
cls, values: Dict[str, Any]
) -> Dict[str, Any]:
if values.get("start_of_range", 0.0) > values.get("end_of_range", 0.0):
raise ValueError(
cls, "start_of_range should not be higher than end_of_range"
)
@model_validator(mode="after")
def validate_start_end_order(self) -> Self: # pylint: disable=duplicate-code
if self.start_of_range > self.end_of_range:
raise ValueError(self, "start_of_range should not be higher than end_of_range")

return values
return self

def __hash__(self) -> int:
return hash(f"{self.start_of_range}|{self.end_of_range}")

def __eq__(self, other: Any) -> bool:
if isinstance(other, NumberRange):
return (
self.start_of_range == other.start_of_range
and self.end_of_range == other.end_of_range
)
return self.start_of_range == other.start_of_range and self.end_of_range == other.end_of_range

return False
10 changes: 4 additions & 6 deletions src/s2python/common/power_forecast.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,8 @@

@catch_and_convert_exceptions
class PowerForecast(GenPowerForecast, S2Message["PowerForecast"]):
class Config(GenPowerForecast.Config):
validate_assignment = True
model_config = GenPowerForecast.model_config
model_config["validate_assignment"] = True

message_id: uuid.UUID = GenPowerForecast.__fields__["message_id"].field_info # type: ignore[assignment]
elements: List[PowerForecastElement] = GenPowerForecast.__fields__[
"elements"
].field_info # type: ignore[assignment]
message_id: uuid.UUID = GenPowerForecast.model_fields["message_id"] # type: ignore[assignment]
elements: List[PowerForecastElement] = GenPowerForecast.model_fields["elements"] # type: ignore[assignment]
10 changes: 5 additions & 5 deletions src/s2python/common/power_forecast_element.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@

@catch_and_convert_exceptions
class PowerForecastElement(GenPowerForecastElement, S2Message["PowerForecastElement"]):
class Config(GenPowerForecastElement.Config):
validate_assignment = True
model_config = GenPowerForecastElement.model_config
model_config["validate_assignment"] = True

duration: Duration = GenPowerForecastElement.__fields__["duration"].field_info # type: ignore[assignment]
power_values: List[PowerForecastValue] = GenPowerForecastElement.__fields__[
duration: Duration = GenPowerForecastElement.model_fields["duration"] # type: ignore[assignment]
power_values: List[PowerForecastValue] = GenPowerForecastElement.model_fields[
"power_values"
].field_info # type: ignore[assignment]
] # type: ignore[assignment]
4 changes: 2 additions & 2 deletions src/s2python/common/power_forecast_value.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@

@catch_and_convert_exceptions
class PowerForecastValue(GenPowerForecastValue, S2Message["PowerForecastValue"]):
class Config(GenPowerForecastValue.Config):
validate_assignment = True
model_config = GenPowerForecastValue.model_config
model_config["validate_assignment"] = True
8 changes: 4 additions & 4 deletions src/s2python/common/power_measurement.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@

@catch_and_convert_exceptions
class PowerMeasurement(GenPowerMeasurement, S2Message["PowerMeasurement"]):
class Config(GenPowerMeasurement.Config):
validate_assignment = True
model_config = GenPowerMeasurement.model_config
model_config["validate_assignment"] = True

message_id: uuid.UUID = GenPowerMeasurement.__fields__["message_id"].field_info # type: ignore[assignment]
values: List[PowerValue] = GenPowerMeasurement.__fields__["values"].field_info # type: ignore[assignment]
message_id: uuid.UUID = GenPowerMeasurement.model_fields["message_id"] # type: ignore[assignment]
values: List[PowerValue] = GenPowerMeasurement.model_fields["values"] # type: ignore[assignment]
23 changes: 9 additions & 14 deletions src/s2python/common/power_range.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from typing import Any, Dict
from typing_extensions import Self

from pydantic import root_validator
from pydantic import model_validator

from s2python.generated.gen_s2 import PowerRange as GenPowerRange
from s2python.validate_values_mixin import (
Expand All @@ -11,17 +11,12 @@

@catch_and_convert_exceptions
class PowerRange(GenPowerRange, S2Message["PowerRange"]):
class Config(GenPowerRange.Config):
validate_assignment = True
model_config = GenPowerRange.model_config
model_config["validate_assignment"] = True

@root_validator(pre=False)
@classmethod
def validate_start_end_order(
cls, values: Dict[str, Any]
) -> Dict[str, Any]: # pylint: disable=duplicate-code
if values.get("start_of_range", 0.0) > values.get("end_of_range", 0.0):
raise ValueError(
cls, "start_of_range should not be higher than end_of_range"
)
@model_validator(mode="after")
def validate_start_end_order(self) -> Self:
if self.start_of_range > self.end_of_range:
raise ValueError(self, "start_of_range should not be higher than end_of_range")

return values
return self
4 changes: 2 additions & 2 deletions src/s2python/common/power_value.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@

@catch_and_convert_exceptions
class PowerValue(GenPowerValue, S2Message["PowerValue"]):
class Config(GenPowerValue.Config):
validate_assignment = True
model_config = GenPowerValue.model_config
model_config["validate_assignment"] = True
8 changes: 3 additions & 5 deletions src/s2python/common/reception_status.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@

@catch_and_convert_exceptions
class ReceptionStatus(GenReceptionStatus, S2Message["ReceptionStatus"]):
class Config(GenReceptionStatus.Config):
validate_assignment = True
model_config = GenReceptionStatus.model_config
model_config["validate_assignment"] = True

subject_message_id: uuid.UUID = GenReceptionStatus.__fields__[
"subject_message_id"
].field_info # type: ignore[assignment]
subject_message_id: uuid.UUID = GenReceptionStatus.model_fields["subject_message_id"] # type: ignore[assignment]
18 changes: 8 additions & 10 deletions src/s2python/common/resource_manager_details.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,13 @@


@catch_and_convert_exceptions
class ResourceManagerDetails(
GenResourceManagerDetails, S2Message["ResourceManagerDetails"]
):
class Config(GenResourceManagerDetails.Config):
validate_assignment = True
class ResourceManagerDetails(GenResourceManagerDetails, S2Message["ResourceManagerDetails"]):
model_config = GenResourceManagerDetails.model_config
model_config["validate_assignment"] = True

instruction_processing_delay: Duration = GenResourceManagerDetails.__fields__[
instruction_processing_delay: Duration = GenResourceManagerDetails.model_fields[
"instruction_processing_delay"
].field_info # type: ignore[assignment]
message_id: uuid.UUID = GenResourceManagerDetails.__fields__["message_id"].field_info # type: ignore[assignment]
resource_id: uuid.UUID = GenResourceManagerDetails.__fields__["resource_id"].field_info # type: ignore[assignment]
roles: List[Role] = GenResourceManagerDetails.__fields__["roles"].field_info # type: ignore[assignment]
] # type: ignore[assignment]
message_id: uuid.UUID = GenResourceManagerDetails.model_fields["message_id"] # type: ignore[assignment]
resource_id: uuid.UUID = GenResourceManagerDetails.model_fields["resource_id"] # type: ignore[assignment]
roles: List[Role] = GenResourceManagerDetails.model_fields["roles"] # type: ignore[assignment]
8 changes: 4 additions & 4 deletions src/s2python/common/revoke_object.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@

@catch_and_convert_exceptions
class RevokeObject(GenRevokeObject, S2Message["RevokeObject"]):
class Config(GenRevokeObject.Config):
validate_assignment = True
model_config = GenRevokeObject.model_config
model_config["validate_assignment"] = True

message_id: uuid.UUID = GenRevokeObject.__fields__["message_id"].field_info # type: ignore[assignment]
object_id: uuid.UUID = GenRevokeObject.__fields__["object_id"].field_info # type: ignore[assignment]
message_id: uuid.UUID = GenRevokeObject.model_fields["message_id"] # type: ignore[assignment]
object_id: uuid.UUID = GenRevokeObject.model_fields["object_id"] # type: ignore[assignment]
4 changes: 2 additions & 2 deletions src/s2python/common/role.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@

@catch_and_convert_exceptions
class Role(GenRole, S2Message["Role"]):
class Config(GenRole.Config):
validate_assignment = True
model_config = GenRole.model_config
model_config["validate_assignment"] = True
6 changes: 3 additions & 3 deletions src/s2python/common/select_control_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

@catch_and_convert_exceptions
class SelectControlType(GenSelectControlType, S2Message["SelectControlType"]):
class Config(GenSelectControlType.Config):
validate_assignment = True
model_config = GenSelectControlType.model_config
model_config["validate_assignment"] = True

message_id: uuid.UUID = GenSelectControlType.__fields__["message_id"].field_info # type: ignore[assignment]
message_id: uuid.UUID = GenSelectControlType.model_fields["message_id"] # type: ignore[assignment]
6 changes: 3 additions & 3 deletions src/s2python/common/session_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

@catch_and_convert_exceptions
class SessionRequest(GenSessionRequest, S2Message["SessionRequest"]):
class Config(GenSessionRequest.Config):
validate_assignment = True
model_config = GenSessionRequest.model_config
model_config["validate_assignment"] = True

message_id: uuid.UUID = GenSessionRequest.__fields__["message_id"].field_info # type: ignore[assignment]
message_id: uuid.UUID = GenSessionRequest.model_fields["message_id"] # type: ignore[assignment]
8 changes: 4 additions & 4 deletions src/s2python/common/timer.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@

@catch_and_convert_exceptions
class Timer(GenTimer, S2Message["Timer"]):
class Config(GenTimer.Config):
validate_assignment = True
model_config = GenTimer.model_config
model_config["validate_assignment"] = True

id: uuid.UUID = GenTimer.__fields__["id"].field_info # type: ignore[assignment]
duration: Duration = GenTimer.__fields__["duration"].field_info # type: ignore[assignment]
id: uuid.UUID = GenTimer.model_fields["id"] # type: ignore[assignment]
duration: Duration = GenTimer.model_fields["duration"] # type: ignore[assignment]
20 changes: 9 additions & 11 deletions src/s2python/common/transition.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,14 @@

@catch_and_convert_exceptions
class Transition(GenTransition, S2Message["Transition"]):
class Config(GenTransition.Config):
validate_assignment = True
model_config = GenTransition.model_config
model_config["validate_assignment"] = True

id: uuid.UUID = GenTransition.__fields__["id"].field_info # type: ignore[assignment]
from_: uuid.UUID = GenTransition.__fields__["from_"].field_info # type: ignore[assignment]
to: uuid.UUID = GenTransition.__fields__["to"].field_info # type: ignore[assignment]
start_timers: List[uuid.UUID] = GenTransition.__fields__["start_timers"].field_info # type: ignore[assignment]
blocking_timers: List[uuid.UUID] = GenTransition.__fields__[
"blocking_timers"
].field_info # type: ignore[assignment]
transition_duration: Optional[Duration] = GenTransition.__fields__[
id: uuid.UUID = GenTransition.model_fields["id"] # type: ignore[assignment]
from_: uuid.UUID = GenTransition.model_fields["from_"] # type: ignore[assignment]
to: uuid.UUID = GenTransition.model_fields["to"] # type: ignore[assignment]
start_timers: List[uuid.UUID] = GenTransition.model_fields["start_timers"] # type: ignore[assignment]
blocking_timers: List[uuid.UUID] = GenTransition.model_fields["blocking_timers"] # type: ignore[assignment]
transition_duration: Optional[Duration] = GenTransition.model_fields[
"transition_duration"
].field_info # type: ignore[assignment]
] # type: ignore[assignment]
Loading