Skip to content

Commit

Permalink
Merge pull request #776 from pyvisa/mypy-fixes
Browse files Browse the repository at this point in the history
Mypy fixes
  • Loading branch information
MatthieuDartiailh committed Oct 13, 2023
2 parents 2220630 + 9d1f006 commit 088f591
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
1 change: 0 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ classifiers = [
]
dependencies = [
"typing_extensions",
"importlib-metadata; python_version<'3.8'",
]
dynamic=["version"]

Expand Down
12 changes: 9 additions & 3 deletions pyvisa/attributes.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,6 @@ class Attribute(Generic[T]):
write: ClassVar[bool] = False
local: ClassVar[bool] = False

__doc__: str

@classmethod
def __init_subclass__(cls, **kwargs):
"""Register the subclass with the supported resources."""
Expand All @@ -123,6 +121,7 @@ def __init_subclass__(cls, **kwargs):
@classmethod
def redoc(cls) -> None:
"""Generate a descriptive docstring."""
assert cls.__doc__ is not None
cls.__doc__ += "\n:VISA Attribute: %s (%s)" % (cls.visa_name, cls.attribute_id)

def post_get(self, value: Any) -> T:
Expand Down Expand Up @@ -215,6 +214,7 @@ class EnumAttribute(Attribute):
@classmethod
def redoc(cls) -> None:
"""Add the enum member to the docstring."""
assert cls.__doc__ is not None
super(EnumAttribute, cls).redoc()
cls.__doc__ += "\n:type: :class:%s.%s" % (
cls.enum_type.__module__,
Expand Down Expand Up @@ -247,6 +247,7 @@ class FlagAttribute(Attribute):
@classmethod
def redoc(cls) -> None:
"""Add the enum member to the docstring."""
assert cls.__doc__ is not None
super(FlagAttribute, cls).redoc()
cls.__doc__ += "\n:type: :class:%s.%s" % (
cls.enum_type.__module__,
Expand Down Expand Up @@ -276,6 +277,7 @@ class IntAttribute(Attribute):
@classmethod
def redoc(cls) -> None:
"""Add the type of the returned value."""
assert cls.__doc__ is not None
super(IntAttribute, cls).redoc()
cls.__doc__ += "\n:type: int"

Expand All @@ -295,6 +297,7 @@ class RangeAttribute(IntAttribute):
@classmethod
def redoc(cls) -> None:
"""Specify the range of validity for the attribute."""
assert cls.__doc__ is not None
super(RangeAttribute, cls).redoc()
cls.__doc__ += "\n:range: %s <= value <= %s" % (cls.min_value, cls.max_value)
if cls.values:
Expand Down Expand Up @@ -332,7 +335,8 @@ class ValuesAttribute(Attribute):

@classmethod
def redoc(cls) -> None:
"""Add the allowed values to teh docs."""
"""Add the allowed values to the docs."""
assert cls.__doc__ is not None
super(ValuesAttribute, cls).redoc()
cls.__doc__ += "\n:values: %s" % cls.values

Expand All @@ -354,6 +358,7 @@ class BooleanAttribute(Attribute):
@classmethod
def redoc(cls) -> None:
"""Add the type to the docs."""
assert cls.__doc__ is not None
super(BooleanAttribute, cls).redoc()
cls.__doc__ += "\n:type: bool"

Expand All @@ -374,6 +379,7 @@ class CharAttribute(Attribute):
@classmethod
def redoc(cls) -> None:
"""Specify the valid characters."""
assert cls.__doc__ is not None
super(CharAttribute, cls).redoc()
cls.__doc__ += "\nASCII Character\n:type: str | bytes"

Expand Down
2 changes: 1 addition & 1 deletion pyvisa/testsuite/test_rname.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def test_handling_duplicate(self):
rname.register_subclass(rname.GPIBInstr)
assert "Class already registered for" in e.exconly()

def test_handling_duplicate_default(self):
def test_handling_duplicate_default(self) -> None:
"""Test we enforce the unicity of default resource class per interface."""
with pytest.raises(ValueError) as e:

Expand Down

0 comments on commit 088f591

Please sign in to comment.