Skip to content

Commit

Permalink
mypy: add some initial typo annotations
Browse files Browse the repository at this point in the history
mypy was unable to infer these types, so specifiy them explicitly.

Signed-off-by: Jan Luebbe <jlu@pengutronix.de>
  • Loading branch information
jluebbe authored and Emantor committed Sep 15, 2021
1 parent 3b28f89 commit 0bb5da5
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 9 deletions.
3 changes: 2 additions & 1 deletion labgrid/binding.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import enum
from functools import wraps
from typing import Any, Dict

import attr

Expand Down Expand Up @@ -36,7 +37,7 @@ class BindingMixin:
callback).
"""

bindings = {}
bindings: Dict[str, Any] = {}

# these are controlled by the Target
target = attr.ib()
Expand Down
3 changes: 2 additions & 1 deletion labgrid/environment.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import os
from typing import Optional
import attr

from .target import Target
Expand Down Expand Up @@ -34,7 +35,7 @@ def __attrs_post_init__(self):
module = importlib.import_module(user_import)
sys.modules[module_name] = module

def get_target(self, role: str = 'main') -> Target:
def get_target(self, role: str = 'main') -> Optional[Target]:
"""Returns the specified target or None if not found.
Each target is initialized as needed.
Expand Down
3 changes: 2 additions & 1 deletion labgrid/remote/exporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import shutil
import subprocess
import warnings
from typing import Dict, Type
from socket import gethostname, getfqdn
import attr
from autobahn.asyncio.wamp import ApplicationRunner, ApplicationSession
Expand All @@ -27,7 +28,7 @@
__version__ = "unknown"


exports = {}
exports: Dict[str, Type[ResourceEntry]] = {}
reexec = False

class ExporterError(Exception):
Expand Down
11 changes: 6 additions & 5 deletions labgrid/resource/common.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from typing import Dict, Type
import attr

from ..binding import BindingMixin
Expand Down Expand Up @@ -81,24 +82,24 @@ def command_prefix(self):

@attr.s(eq=False)
class ResourceManager:
instances = {}
instances: 'Dict[Type[ResourceManager], ResourceManager]' = {}

@classmethod
def get(cls):
def get(cls) -> 'ResourceManager':
instance = ResourceManager.instances.get(cls)
if instance is None:
instance = cls()
ResourceManager.instances[cls] = instance
return instance

def __attrs_post_init__(self):
self.resources = []
self.resources: List[ManagedResource] = []

def _add_resource(self, resource):
def _add_resource(self, resource: 'ManagedResource'):
self.resources.append(resource)
self.on_resource_added(resource)

def on_resource_added(self, resource):
def on_resource_added(self, resource: 'ManagedResource'):
pass

def poll(self):
Expand Down
3 changes: 2 additions & 1 deletion labgrid/util/ssh.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import os
from select import select
from functools import wraps
from typing import Dict

import attr
from ..driver.exception import ExecutionError
Expand All @@ -22,7 +23,7 @@ class SSHConnectionManager:
should not be directly instantiated, use the exported sshmanager from this
module instead.
"""
_connections = attr.ib(
_connections: 'Dict[str, SSHConnection]' = attr.ib(
default=attr.Factory(dict),
init=False,
validator=attr.validators.optional(attr.validators.instance_of(dict))
Expand Down
2 changes: 2 additions & 0 deletions mypy.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[mypy]
ignore_missing_imports = True

0 comments on commit 0bb5da5

Please sign in to comment.