Skip to content

Commit

Permalink
Fixed annotation for Python 3.8.
Browse files Browse the repository at this point in the history
  • Loading branch information
lextm committed Feb 13, 2024
1 parent 32e26e3 commit 14735e0
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 19 deletions.
6 changes: 4 additions & 2 deletions pysnmp/entity/engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ class SnmpEngine:
"""

transportDispatcher: AbstractTransportDispatcher | None
transportDispatcher: "AbstractTransportDispatcher | None"

def __init__(
self, snmpEngineID=None, maxMessageSize: int = 65507, msgAndPduDsp=None
Expand Down Expand Up @@ -215,7 +215,9 @@ def getMibBuilder(self):
def setUserContext(self, **kwargs):
self.cache.update({"__%s" % k: kwargs[k] for k in kwargs})

def getUserContext(self, arg) -> Dict[str, Any] | None: # TODO: fix this type check
def getUserContext(
self, arg
) -> "Dict[str, Any] | None": # TODO: fix this type check
return self.cache.get("__%s" % arg)

def delUserContext(self, arg):
Expand Down
8 changes: 4 additions & 4 deletions pysnmp/entity/rfc3413/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def getTargetAddr(snmpEngine: SnmpEngine, snmpTargetAddrName):

cache = snmpEngine.getUserContext("getTargetAddr")
if cache is None:
cache: Dict[str, Any] | None = {"id": -1}
cache: "Dict[str, Any] | None" = {"id": -1}
snmpEngine.setUserContext(getTargetAddr=cache)

if cache["id"] != snmpTargetAddrEntry.branchVersionId:
Expand Down Expand Up @@ -119,7 +119,7 @@ def getTargetParams(snmpEngine: SnmpEngine, paramsName):

cache = snmpEngine.getUserContext("getTargetParams")
if cache is None:
cache: Dict[str, Any] | None = {"id": -1}
cache: "Dict[str, Any] | None" = {"id": -1}
snmpEngine.setUserContext(getTargetParams=cache)

if cache["id"] != snmpTargetParamsEntry.branchVersionId:
Expand Down Expand Up @@ -209,7 +209,7 @@ def getNotificationInfo(snmpEngine: SnmpEngine, notificationTarget):

cache = snmpEngine.getUserContext("getNotificationInfo")
if cache is None:
cache: Dict[str, Any] | None = {"id": -1}
cache: "Dict[str, Any] | None" = {"id": -1}
snmpEngine.setUserContext(getNotificationInfo=cache)

if cache["id"] != snmpNotifyEntry.branchVersionId:
Expand Down Expand Up @@ -247,7 +247,7 @@ def getTargetNames(snmpEngine: SnmpEngine, tag):

cache = snmpEngine.getUserContext("getTargetNames")
if cache is None:
cache: Dict[str, Any] | None = {"id": -1}
cache: "Dict[str, Any] | None" = {"id": -1}
snmpEngine.setUserContext(getTargetNames=cache)

if cache["id"] == snmpTargetAddrEntry.branchVersionId:
Expand Down
22 changes: 14 additions & 8 deletions pysnmp/hlapi/asyncio/cmdgen.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@

async def getCmd(
snmpEngine: SnmpEngine,
authData: CommunityData | UsmUserData,
authData: "CommunityData | UsmUserData",
transportTarget: AbstractTransportTarget,
contextData: ContextData,
*varBinds,
Expand Down Expand Up @@ -177,7 +177,7 @@ def __cbFun(

async def setCmd(
snmpEngine: SnmpEngine,
authData: CommunityData | UsmUserData,
authData: "CommunityData | UsmUserData",
transportTarget: AbstractTransportTarget,
contextData: ContextData,
*varBinds,
Expand Down Expand Up @@ -297,7 +297,7 @@ def __cbFun(

async def nextCmd(
snmpEngine: SnmpEngine,
authData: CommunityData | UsmUserData,
authData: "CommunityData | UsmUserData",
transportTarget: AbstractTransportTarget,
contextData: ContextData,
*varBinds,
Expand Down Expand Up @@ -395,8 +395,11 @@ def __cbFun(
lookupMib, future = cbCtx
if future.cancelled():
return
if (options.get('ignoreNonIncreasingOid', False) and
errorIndication and isinstance(errorIndication, errind.OidNotIncreasing)):
if (
options.get("ignoreNonIncreasingOid", False)
and errorIndication
and isinstance(errorIndication, errind.OidNotIncreasing)
):
errorIndication = None
try:
varBindsUnmade = [
Expand Down Expand Up @@ -431,7 +434,7 @@ def __cbFun(

async def bulkCmd(
snmpEngine: SnmpEngine,
authData: CommunityData | UsmUserData,
authData: "CommunityData | UsmUserData",
transportTarget: AbstractTransportTarget,
contextData: ContextData,
nonRepeaters: int,
Expand Down Expand Up @@ -560,8 +563,11 @@ def __cbFun(
lookupMib, future = cbCtx
if future.cancelled():
return
if (options.get('ignoreNonIncreasingOid', False) and
errorIndication and isinstance(errorIndication, errind.OidNotIncreasing)):
if (
options.get("ignoreNonIncreasingOid", False)
and errorIndication
and isinstance(errorIndication, errind.OidNotIncreasing)
):
errorIndication = None
try:
varBindsUnmade = [
Expand Down
2 changes: 1 addition & 1 deletion pysnmp/hlapi/asyncio/transport.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class instance.
transportDomain: Tuple[int, ...] = udp.domainName
protoTransport = udp.UdpAsyncioTransport

def _resolveAddr(self, transportAddr: tuple) -> tuple[str, int]:
def _resolveAddr(self, transportAddr: Tuple) -> Tuple[str, int]:
try:
return socket.getaddrinfo(
transportAddr[0],
Expand Down
9 changes: 5 additions & 4 deletions pysnmp/hlapi/transport.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
# Copyright (c) 2005-2019, Ilya Etingof <[email protected]>
# License: https://www.pysnmp.com/pysnmp/license.html
#
from typing import Tuple
from pyasn1.compat.octets import null
from pysnmp.carrier.base import AbstractTransport, AbstractTransportAddress
from pysnmp import error
Expand All @@ -16,15 +17,15 @@ class AbstractTransportTarget:

retries: int
timeout: float
transport: AbstractTransport | None
transportAddr: tuple[str, int]
transport: "AbstractTransport | None"
transportAddr: Tuple[str, int]

transportDomain = None
protoTransport = AbstractTransport

def __init__(
self,
transportAddr: tuple,
transportAddr: Tuple,
timeout: float = 1,
retries: int = 5,
tagList=null,
Expand Down Expand Up @@ -79,5 +80,5 @@ def verifyDispatcherCompatibility(self, snmpEngine: SnmpEngine):
)
)

def _resolveAddr(self, transportAddr: tuple) -> tuple[str, int]:
def _resolveAddr(self, transportAddr: Tuple) -> Tuple[str, int]:
raise NotImplementedError()

0 comments on commit 14735e0

Please sign in to comment.