Skip to content

Commit

Permalink
Fix type hint for DataTransfer.data
Browse files Browse the repository at this point in the history
This field doesn't have any constraints. It can be anything.
  • Loading branch information
OrangeTux committed Jul 19, 2023
1 parent a816bad commit b8230eb
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 16 deletions.
5 changes: 2 additions & 3 deletions ocpp/v21/call.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from dataclasses import dataclass
from typing import List, Optional
from typing import Any, List, Optional

from datatypes import (
AuthorizationData,
Expand Down Expand Up @@ -34,7 +34,6 @@
SetMonitoringData,
SetVariableData,
TransactionInfo,
data,
)

import enums
Expand Down Expand Up @@ -164,7 +163,7 @@ class CustomerInformation:
class DataTransfer:
vendor_id: str
custom_data: Optional[CustomData] = None
data: Optional[data] = None
data: Optional[Any] = None
message_id: Optional[str] = None


Expand Down
5 changes: 2 additions & 3 deletions ocpp/v21/call_result.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from dataclasses import dataclass
from typing import List, Optional
from typing import Any, List, Optional

from datatypes import (
CertificateHashDataChain,
Expand All @@ -12,7 +12,6 @@
SetVariableResult,
StatusInfo,
UpdatedPersonalMessage,
data,
)

import enums
Expand Down Expand Up @@ -147,7 +146,7 @@ class CustomerInformation:
class DataTransfer:
status: DataTransferStatus
custom_data: Optional[CustomData] = None
data: Optional[data] = None
data: Optional[Any] = None
status_info: Optional[StatusInfo] = None


Expand Down
18 changes: 8 additions & 10 deletions scripts/v21/code_generator.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,6 @@
import re

from .json_schema_types import (
Object,
Enum,
String,
Boolean,
Number,
Integer,
Array,
)
from json_schema_types import Array, Boolean, Enum, Integer, Number, Object, String

# Tab's are 4 spaces.
TAB = " "
Expand Down Expand Up @@ -71,7 +63,7 @@ def _generate_messages(messages: list[Object]) -> str:

code = ""
code += "from dataclasses import dataclass\n"
code += "from typing import List, Optional\n"
code += "from typing import Any, List, Optional\n"
imports = generate_import_statement_for_external_objects(objects)
if imports != "":
code += "\n"
Expand Down Expand Up @@ -212,6 +204,9 @@ def _get_python_type(value) -> str:
return f"List[{_get_python_type(value.type)}]"

if isinstance(value, Object):
if value.name == "data" and len(value.properties) == 0:
return "Any"

return value.name

if isinstance(value, Enum):
Expand Down Expand Up @@ -277,6 +272,9 @@ def generate_import_statement_for_external_objects(objects: list[Object]) -> str

code = "from datatypes import (\n"
for object in objects:
if object.name == "data" and len(object.properties) == 0:
continue

code += f"{TAB}{object.name},\n"
code += ")\n"

Expand Down

0 comments on commit b8230eb

Please sign in to comment.