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

Workaround broken docstrings in the python std library #5979

Merged
merged 3 commits into from
Apr 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
7 changes: 1 addition & 6 deletions .github/workflows/docs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,7 @@ jobs:
python-version: 3.11
env:
OS: ${{ matrix.os }}
# The std-lib docstring of Int is not valid
# causing errors like in the docstring of from_bytes (from Int)
# WARNING: Inline interpreted text or phrase reference start-string without end-string.
# when documenting subclasses of IntFlag such as in the lakeshore driver.
# see https://github.com/python/cpython/pull/117847
SPHINX_WARNINGS_AS_ERROR: false
SPHINX_WARNINGS_AS_ERROR: true
SPHINX_OPTS: "-v -j 2"
steps:
- name: Harden Runner
Expand Down
68 changes: 67 additions & 1 deletion src/qcodes/instrument_drivers/Lakeshore/Lakeshore_model_325.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
from enum import IntFlag
from itertools import takewhile
from typing import TYPE_CHECKING, Any, Optional, TextIO, cast
from typing import (
TYPE_CHECKING,
Any,
Literal,
Optional,
SupportsBytes,
SupportsIndex,
TextIO,
Union,
cast,
)

from qcodes.instrument import ChannelList, InstrumentChannel, VisaInstrument
from qcodes.parameters import Group, GroupParameter
Expand All @@ -9,6 +19,8 @@
if TYPE_CHECKING:
from collections.abc import Iterable

from typing_extensions import Buffer, Self


def _read_curve_file(curve_file: TextIO) -> dict[Any, Any]:
"""
Expand Down Expand Up @@ -79,6 +91,60 @@
temp_underrange = 16
invalid_reading = 1

# we reimplement from_bytes and to_bytes in order to fix docstrings that are incorrectly formatted
# this in turn will enable us to build docs with warnings as errors.
# This can be removed for python versions where https://github.com/python/cpython/pull/117847
# is merged
@classmethod
def from_bytes(
cls: "type[Self]",
bytes: "Union[Iterable[SupportsIndex], SupportsBytes, Buffer]",
byteorder: Literal["big", "little"] = "big",
*,
signed: bool = False,
) -> "Self":
"""
Return the integer represented by the given array of bytes.

Args:
bytes: Holds the array of bytes to convert. The argument must either
support the buffer protocol or be an iterable object producing bytes.
Bytes and bytearray are examples of built-in objects that support the
buffer protocol.
byteorder: The byte order used to represent the integer. If byteorder is 'big',
the most significant byte is at the beginning of the byte array. If
byteorder is 'little', the most significant byte is at the end of the
byte array. To request the native byte order of the host system, use
`sys.byteorder` as the byte order value. Default is to use 'big'.
signed: Indicates whether two\'s complement is used to represent the integer.
"""
return super().from_bytes(bytes, byteorder, signed=signed)

Check warning on line 121 in src/qcodes/instrument_drivers/Lakeshore/Lakeshore_model_325.py

View check run for this annotation

Codecov / codecov/patch

src/qcodes/instrument_drivers/Lakeshore/Lakeshore_model_325.py#L121

Added line #L121 was not covered by tests

def to_bytes(
self,
length: SupportsIndex = 1,
byteorder: Literal["little", "big"] = "big",
*,
signed: bool = False,
) -> bytes:
"""
Return an array of bytes representing an integer.

Args:
length: Length of bytes object to use. An OverflowError is raised if the
integer is not representable with the given number of bytes. Default
is length 1.
byteorder: The byte order used to represent the integer. If byteorder is \'big\',
the most significant byte is at the beginning of the byte array. If
byteorder is \'little\', the most significant byte is at the end of the
byte array. To request the native byte order of the host system, use
`sys.byteorder` as the byte order value. Default is to use \'big\'.
signed: Determines whether two\'s complement is used to represent the integer.
If signed is False and a negative integer is given, an OverflowError
is raised.
"""
return super().to_bytes(length, byteorder, signed=signed)

Check warning on line 146 in src/qcodes/instrument_drivers/Lakeshore/Lakeshore_model_325.py

View check run for this annotation

Codecov / codecov/patch

src/qcodes/instrument_drivers/Lakeshore/Lakeshore_model_325.py#L146

Added line #L146 was not covered by tests


class LakeshoreModel325Curve(InstrumentChannel):
"""
Expand Down
Loading