Skip to content

Commit

Permalink
fix(plc4py): Replace builtin types (list and dict) with class from th…
Browse files Browse the repository at this point in the history
…e typing package.
  • Loading branch information
hutcheb committed Nov 14, 2022
1 parent df10651 commit 135452d
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 12 deletions.
4 changes: 2 additions & 2 deletions sandbox/plc4py/plc4py/PlcDriverManager.py
Expand Up @@ -20,7 +20,7 @@
import logging
from contextlib import asynccontextmanager
from dataclasses import dataclass, field
from typing import Type, AsyncIterator
from typing import Type, AsyncIterator, List
from pluggy import PluginManager # type: ignore

from plc4py.api.PlcConnection import PlcConnection
Expand Down Expand Up @@ -78,7 +78,7 @@ async def get_connection(self, url: str) -> PlcConnection:
protocol_code = get_protocol_code(url)
return await self._driverMap[protocol_code]().get_connection(url)

def list_drivers(self) -> list[str]:
def list_drivers(self) -> List[str]:
"""
Returns the codes of the drivers which are currently registered at the PlcDriverManager
:return: Set of driver codes for all drivers registered
Expand Down
4 changes: 2 additions & 2 deletions sandbox/plc4py/plc4py/api/messages/PlcRequest.py
Expand Up @@ -18,7 +18,7 @@
#
from abc import abstractmethod
from dataclasses import dataclass, field
from typing import Union
from typing import Union, List

from plc4py.api.messages.PlcField import PlcField
from plc4py.api.messages.PlcMessage import PlcMessage
Expand All @@ -33,7 +33,7 @@ class PlcRequest(PlcMessage):

@dataclass
class PlcFieldRequest(PlcRequest):
fields: list[PlcField] = field(default_factory=lambda: [])
fields: List[PlcField] = field(default_factory=lambda: [])

@property
def field_names(self):
Expand Down
6 changes: 3 additions & 3 deletions sandbox/plc4py/plc4py/api/messages/PlcResponse.py
Expand Up @@ -17,7 +17,7 @@
# under the License.
#
from dataclasses import dataclass
from typing import cast
from typing import cast, List, Dict

from plc4py.api.messages.PlcField import PlcField
from plc4py.api.messages.PlcMessage import PlcMessage
Expand All @@ -37,7 +37,7 @@ class PlcResponse(PlcMessage):

@dataclass
class PlcFieldResponse(PlcResponse):
fields: list[PlcField]
fields: List[PlcField]

@property
def field_names(self):
Expand All @@ -53,7 +53,7 @@ class PlcReadResponse(PlcFieldResponse):
Response to a {@link PlcReadRequest}.
"""

values: dict[str, list[ResponseItem[PlcValue]]]
values: Dict[str, List[ResponseItem[PlcValue]]]

def get_plc_value(self, name: str, index: int = 0) -> PlcValue:
return self.values[name][index].value
Expand Down
4 changes: 2 additions & 2 deletions sandbox/plc4py/plc4py/drivers/mock/MockConnection.py
Expand Up @@ -20,7 +20,7 @@
import asyncio
import logging
from dataclasses import dataclass, field
from typing import Awaitable, Type
from typing import Awaitable, Type, List

import plc4py

Expand Down Expand Up @@ -75,7 +75,7 @@ def of(fieldquery: str) -> MockPlcField:
class MockDevice:
fields: dict[str, PlcValue] = field(default_factory=lambda: {})

def read(self, field: str) -> list[ResponseItem[PlcValue]]:
def read(self, field: str) -> List[ResponseItem[PlcValue]]:
"""
Reads one field from the Mock Device
"""
Expand Down
6 changes: 3 additions & 3 deletions sandbox/plc4py/plc4py/drivers/mock/MockReadRequestBuilder.py
Expand Up @@ -18,7 +18,7 @@
#

from dataclasses import dataclass, field
from typing import Union
from typing import Union, List

from plc4py.api.messages.PlcMessage import PlcMessage
from plc4py.api.messages.PlcRequest import (
Expand All @@ -35,13 +35,13 @@ def get_request(self) -> PlcMessage:


class MockPlcReadRequest(PlcReadRequest):
def __init__(self, fields: list[PlcField] = []):
def __init__(self, fields: List[PlcField] = []):
super().__init__(fields)


@dataclass
class MockReadRequestBuilder(ReadRequestBuilder):
items: list[PlcField] = field(default_factory=lambda: [])
items: List[PlcField] = field(default_factory=lambda: [])

def build(self) -> PlcReadRequest:
return MockPlcReadRequest(self.items)
Expand Down

0 comments on commit 135452d

Please sign in to comment.