Skip to content
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

add type hints around crypto module #1714

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
fix circular import
  • Loading branch information
jbeckerwsi committed Oct 2, 2024
commit 73f37c76f74ee76ff229436f06f50332963cbd15
8 changes: 4 additions & 4 deletions asyncua/common/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def is_chunk_count_within_limit(self, sz: int) -> bool:
_logger.error("Number of message chunks: %s is > configured max chunk count: %s", sz, self.max_chunk_count)
return within_limit

def create_acknowledge_and_set_limits(self, msg: ua.Hello) -> ua.Acknowledge:
def create_acknowledge_and_set_limits(self, msg: "ua.Hello") -> "ua.Acknowledge":
Copy link
Member

Choose a reason for hiding this comment

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

that too cannot be correct. should be possible to use from __future__ import annotations stuff to avoid adding "

Copy link
Member

Choose a reason for hiding this comment

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

there should be no reason to use " for typing

ack = ua.Acknowledge()
ack.ReceiveBufferSize = min(msg.ReceiveBufferSize, self.max_send_buffer)
ack.SendBufferSize = min(msg.SendBufferSize, self.max_recv_buffer)
Expand All @@ -69,14 +69,14 @@ def create_acknowledge_and_set_limits(self, msg: ua.Hello) -> ua.Acknowledge:
_logger.info("updating server limits to: %s", self)
return ack

def create_hello_limits(self, msg: ua.Hello) -> ua.Hello:
def create_hello_limits(self, msg: "ua.Hello") -> "ua.Hello":
msg.ReceiveBufferSize = self.max_recv_buffer
msg.SendBufferSize = self.max_send_buffer
msg.MaxChunkCount = self.max_chunk_count
msg.MaxMessageSize = self.max_chunk_count
return msg

def update_client_limits(self, msg: ua.Acknowledge) -> None:
def update_client_limits(self, msg: "ua.Acknowledge") -> None:
self.max_chunk_count = msg.MaxChunkCount
self.max_recv_buffer = msg.ReceiveBufferSize
self.max_send_buffer = msg.SendBufferSize
Expand Down Expand Up @@ -394,7 +394,7 @@ def _check_incoming_chunk(self, chunk):
raise ua.UaError(f"Received chunk: {chunk} with wrong sequence expecting:" f" {self._peer_sequence_number}, received: {seq_num}," f" spec says to close connection")
self._peer_sequence_number = seq_num

def receive_from_header_and_body(self, header: ua.Header, body: "Buffer") -> Union[None,ua.Message,ua.Hello,ua.Acknowledge,ua.ErrorMessage]:
def receive_from_header_and_body(self, header: ua.Header, body: "Buffer") -> Union[None,ua.Message,"ua.Hello",ua.Acknowledge,ua.ErrorMessage]:
"""
Convert MessageHeader and binary body to OPC UA TCP message (see OPC UA
specs Part 6, 7.1: Hello, Acknowledge or ErrorMessage), or a Message
Expand Down
7 changes: 2 additions & 5 deletions asyncua/ua/ua_binary.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import struct
import logging
from io import BytesIO
from typing import IO, Any, Callable, Optional, Sequence, Type, TypeVar, Union, TYPE_CHECKING
from typing import IO, Any, Callable, Optional, Sequence, Type, TypeVar, Union
import typing
import uuid
from enum import Enum, IntFlag
Expand All @@ -16,9 +16,6 @@
from ..common.utils import Buffer
from .uatypes import type_from_optional, type_is_list, type_is_union, type_from_list, types_or_list_from_union, type_allow_subclass

if TYPE_CHECKING:
from asyncua.common.utils import Buffer

_logger = logging.getLogger(__name__)

T = TypeVar('T')
Expand Down Expand Up @@ -711,7 +708,7 @@ def header_to_binary(hdr) -> bytes:
return b"".join(b)


def header_from_binary(data) -> ua.Header:
def header_from_binary(data) -> "ua.Header":
hdr = ua.Header()
hdr.MessageType, hdr.ChunkType, hdr.packet_size = struct.unpack("<3scI", data.read(8))
hdr.body_size = hdr.packet_size - 8
Expand Down
1 change: 0 additions & 1 deletion asyncua/ua/uaprotocol_hand.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
from dataclasses import dataclass, field
from typing import List, TYPE_CHECKING, Optional, Union

from asyncua.common.connection import MessageChunk
from asyncua.ua import uaprotocol_auto as auto
from asyncua.ua import uatypes
from asyncua.common import utils
Expand Down