Skip to content

Commit

Permalink
add typing (except protocols) and update docstring to use Numpy-style
Browse files Browse the repository at this point in the history
  • Loading branch information
MatthieuDartiailh committed Jul 28, 2020
1 parent f4ef165 commit 2179277
Show file tree
Hide file tree
Showing 15 changed files with 1,574 additions and 799 deletions.
7 changes: 5 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ jobs:
- name: Install tools
run: |
python -m pip install --upgrade pip
pip install flake8 black isort
pip install flake8 black isort mypy
pip install git+https://github.com/pyvisa/pyvisa.git#egg=pyvisa
- name: Isort
run: |
Expand All @@ -41,6 +41,9 @@ jobs:
- name: Flake8
run: |
flake8 pyvisa-py;
- name: Mypy
run: |
mypy pyvisa;
tests:
name: Unit tests
runs-on: ${{ matrix.os }}
Expand Down Expand Up @@ -86,5 +89,5 @@ jobs:
if: needs.tests.result == 'success'
run: exit 0
- name: Mark the job as a failure
if: needs.tests.result == 'failure'
if: needs.tests.result != 'success'
run: exit 1
30 changes: 17 additions & 13 deletions pyvisa-py/common.py
Original file line number Diff line number Diff line change
@@ -1,40 +1,44 @@
# -*- coding: utf-8 -*-
"""
pyvisa-sim.common
~~~~~~~~~~~~~~~~~
"""Common code.
Common code.
:copyright: 2014-2020 by PyVISA-sim Authors, see AUTHORS for more details.
:license: MIT, see LICENSE for more details.
:copyright: 2014-2020 by PyVISA-sim Authors, see AUTHORS for more details.
:license: MIT, see LICENSE for more details.
"""
import logging
from typing import Optional, SupportsBytes

from pyvisa import logger

logger = logging.LoggerAdapter(logger, {"backend": "py"})


class MockInterface(object):
def __init__(self, resource_name):

#: Name of the resource used to create this interface
resource_name: str

def __init__(self, resource_name) -> None:
self.resource_name = resource_name


class NamedObject(object):
"""A class to construct named sentinels.
"""
"""A class to construct named sentinels."""

def __init__(self, name):
#: Name used to identify the sentinel
name: str

def __init__(self, name) -> None:
self.name = name

def __repr__(self):
def __repr__(self) -> str:
return "<%s>" % self.name

__str__ = __repr__


def iter_bytes(data, mask=None, send_end=False):

# XXX can probably be removed
def iter_bytes(data: SupportsBytes, mask: Optional[int] = None, send_end: bool = False):
if send_end and mask is None:
raise ValueError("send_end requires a valid mask.")

Expand Down
Loading

0 comments on commit 2179277

Please sign in to comment.