Skip to content

Commit 8e13f73

Browse files
authored
docs: Use public package/module names more consistently and show type hints in signatures (#153)
* docs: Rework imports to hide private submodules * docs: Show type hints in signatures
1 parent 29659c4 commit 8e13f73

File tree

13 files changed

+161
-46
lines changed

13 files changed

+161
-46
lines changed

docs/conf.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
autoapi_dirs = [root_path / "src" / "nitypes"]
5050
autoapi_own_page_level = "class"
5151
autoapi_type = "python"
52-
autodoc_typehints = "description"
52+
autodoc_typehints = "both"
5353
# Uncomment for debugging
5454
# autoapi_keep_files = True
5555

src/nitypes/bintime/_datetime.py

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,33 @@
22

33
import datetime as dt
44
from functools import singledispatchmethod
5-
from typing import Any, ClassVar, SupportsIndex, Union, cast, final, overload
5+
from typing import (
6+
TYPE_CHECKING,
7+
Any,
8+
ClassVar,
9+
SupportsIndex,
10+
Union,
11+
cast,
12+
final,
13+
overload,
14+
)
615

716
import hightime as ht
817
from typing_extensions import Self, TypeAlias
918

1019
from nitypes._exceptions import invalid_arg_type, invalid_arg_value
11-
from nitypes.bintime._time_value_tuple import TimeValueTuple
1220
from nitypes.bintime._timedelta import (
1321
_OTHER_TIMEDELTA_TUPLE,
14-
TimeDelta,
1522
_OtherTimeDelta,
1623
)
1724

25+
if TYPE_CHECKING:
26+
# Import from the public package so the docs don't reference private submodules.
27+
from nitypes.bintime import TimeDelta, TimeValueTuple
28+
else:
29+
from nitypes.bintime._time_value_tuple import TimeValueTuple
30+
from nitypes.bintime._timedelta import TimeDelta
31+
1832
_DT_EPOCH_1904 = dt.datetime(1904, 1, 1, tzinfo=dt.timezone.utc)
1933
_HT_EPOCH_1904 = ht.datetime(1904, 1, 1, tzinfo=dt.timezone.utc)
2034

src/nitypes/bintime/_timedelta.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,20 @@
66
import operator
77
from decimal import Decimal
88
from functools import singledispatchmethod
9-
from typing import Any, ClassVar, SupportsIndex, Union, final, overload
9+
from typing import TYPE_CHECKING, Any, ClassVar, SupportsIndex, Union, final, overload
1010

1111
import hightime as ht
1212
from typing_extensions import Self, TypeAlias
1313

1414
from nitypes._arguments import arg_to_int
1515
from nitypes._exceptions import int_out_of_range, invalid_arg_type
16-
from nitypes.bintime._time_value_tuple import TimeValueTuple
16+
17+
if TYPE_CHECKING:
18+
# Import from the public package so the docs don't reference private submodules.
19+
from nitypes.bintime import TimeValueTuple
20+
else:
21+
from nitypes.bintime._time_value_tuple import TimeValueTuple
22+
1723

1824
_INT64_MAX = (1 << 63) - 1
1925
_INT64_MIN = -(1 << 63)

src/nitypes/waveform/_analog.py

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,21 @@
55

66
import numpy as np
77
import numpy.typing as npt
8-
from typing_extensions import TypeVar, final, override
8+
from typing_extensions import TypeVar, final, override, TYPE_CHECKING
99

1010
from nitypes._numpy import long as _np_long, ulong as _np_ulong
11-
from nitypes.waveform._extended_properties import ExtendedPropertyValue
12-
from nitypes.waveform._numeric import NumericWaveform, _TOtherScaled
13-
from nitypes.waveform._scaling import ScaleMode
14-
from nitypes.waveform._timing import Timing, _AnyDateTime, _AnyTimeDelta
11+
from nitypes.waveform._numeric import _TOtherScaled
12+
from nitypes.waveform._timing import _AnyDateTime, _AnyTimeDelta
13+
14+
if TYPE_CHECKING:
15+
# Import from the public package so the docs don't reference private submodules.
16+
from nitypes.waveform import ExtendedPropertyValue, NumericWaveform, ScaleMode, Timing
17+
else:
18+
from nitypes.waveform._extended_properties import ExtendedPropertyValue
19+
from nitypes.waveform._numeric import NumericWaveform
20+
from nitypes.waveform._scaling import ScaleMode
21+
from nitypes.waveform._timing import Timing
22+
1523

1624
# _TRaw specifies the type of the raw_data array. AnalogWaveform accepts a narrower set of types
1725
# than NumericWaveform.

src/nitypes/waveform/_complex.py

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,25 @@
55

66
import numpy as np
77
import numpy.typing as npt
8-
from typing_extensions import TypeVar, final, override
8+
from typing_extensions import TYPE_CHECKING, TypeVar, final, override
99

1010
from nitypes.complex import ComplexInt32Base, ComplexInt32DType, convert_complex
11-
from nitypes.waveform._extended_properties import ExtendedPropertyValue
12-
from nitypes.waveform._numeric import NumericWaveform, _TOtherScaled
13-
from nitypes.waveform._scaling import ScaleMode
14-
from nitypes.waveform._timing import Timing, _AnyDateTime, _AnyTimeDelta
11+
from nitypes.waveform._numeric import _TOtherScaled
12+
from nitypes.waveform._timing import _AnyDateTime, _AnyTimeDelta
13+
14+
if TYPE_CHECKING:
15+
# Import from the public package so the docs don't reference private submodules.
16+
from nitypes.waveform import (
17+
ExtendedPropertyValue,
18+
NumericWaveform,
19+
ScaleMode,
20+
Timing,
21+
)
22+
else:
23+
from nitypes.waveform._extended_properties import ExtendedPropertyValue
24+
from nitypes.waveform._numeric import NumericWaveform
25+
from nitypes.waveform._scaling import ScaleMode
26+
from nitypes.waveform._timing import Timing
1527

1628
# _TRaw specifies the type of the raw_data array. ComplexWaveform accepts a narrower set of types
1729
# than NumericWaveform. Note that ComplexInt32Base is an alias for np.void, but other structured

src/nitypes/waveform/_digital/_signal.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,11 @@
99
from nitypes.waveform._digital._types import _TState
1010

1111
if TYPE_CHECKING:
12-
from nitypes.waveform._digital._waveform import DigitalWaveform # circular import
12+
# Import from the public package so the docs don't reference private submodules.
13+
from nitypes.waveform import DigitalWaveform
14+
else:
15+
# DigitalWaveform is a circular import.
16+
pass
1317

1418

1519
class DigitalWaveformSignal(Generic[_TState]):

src/nitypes/waveform/_digital/_signal_collection.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,14 @@
44
from typing import TYPE_CHECKING, Generic, overload
55

66
from nitypes._exceptions import invalid_arg_type
7-
from nitypes.waveform._digital._signal import DigitalWaveformSignal
87
from nitypes.waveform._digital._types import _TState
98

109
if TYPE_CHECKING:
11-
from nitypes.waveform._digital._waveform import DigitalWaveform # circular import
10+
# Import from the public package so the docs don't reference private submodules.
11+
from nitypes.waveform import DigitalWaveform, DigitalWaveformSignal
12+
else:
13+
# DigitalWaveform is a circular import.
14+
from nitypes.waveform._digital._signal import DigitalWaveformSignal
1215

1316

1417
class DigitalWaveformSignalCollection(Generic[_TState], Sequence[DigitalWaveformSignal[_TState]]):

src/nitypes/waveform/_digital/_waveform.py

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import sys
55
from collections.abc import Mapping, Sequence
66
from dataclasses import dataclass
7-
from typing import Any, Generic, SupportsIndex, overload
7+
from typing import TYPE_CHECKING, Any, Generic, SupportsIndex, overload
88

99
import hightime as ht
1010
import numpy as np
@@ -15,8 +15,6 @@
1515
from nitypes._exceptions import invalid_arg_type, invalid_array_ndim
1616
from nitypes._numpy import asarray as _np_asarray
1717
from nitypes.waveform._digital._port import bit_mask, get_port_dtype, port_to_line_data
18-
from nitypes.waveform._digital._signal_collection import DigitalWaveformSignalCollection
19-
from nitypes.waveform._digital._state import DigitalState
2018
from nitypes.waveform._digital._types import (
2119
_DIGITAL_PORT_DTYPES,
2220
_DIGITAL_STATE_DTYPES,
@@ -35,14 +33,32 @@
3533
from nitypes.waveform._extended_properties import (
3634
CHANNEL_NAME,
3735
LINE_NAMES,
38-
ExtendedPropertyDictionary,
39-
ExtendedPropertyValue,
4036
)
41-
from nitypes.waveform._timing import Timing, _AnyDateTime, _AnyTimeDelta
37+
from nitypes.waveform._timing import _AnyDateTime, _AnyTimeDelta
4238

4339
if sys.version_info < (3, 10):
4440
import array as std_array
4541

42+
if TYPE_CHECKING:
43+
# Import from the public package so the docs don't reference private submodules.
44+
from nitypes.waveform import (
45+
DigitalState,
46+
DigitalWaveformSignalCollection,
47+
ExtendedPropertyDictionary,
48+
ExtendedPropertyValue,
49+
Timing,
50+
)
51+
else:
52+
from nitypes.waveform._digital._signal_collection import (
53+
DigitalWaveformSignalCollection,
54+
)
55+
from nitypes.waveform._digital._state import DigitalState
56+
from nitypes.waveform._extended_properties import (
57+
ExtendedPropertyDictionary,
58+
ExtendedPropertyValue,
59+
)
60+
from nitypes.waveform._timing import Timing
61+
4662

4763
@dataclass(frozen=True)
4864
class DigitalWaveformFailure:

src/nitypes/waveform/_numeric.py

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import warnings
66
from abc import ABC, abstractmethod
77
from collections.abc import Mapping, Sequence
8-
from typing import Any, Generic, SupportsIndex, overload
8+
from typing import TYPE_CHECKING, Any, Generic, SupportsIndex, overload
99

1010
import hightime as ht
1111
import numpy as np
@@ -23,19 +23,30 @@
2323
create_start_index_or_sample_count_too_large_error,
2424
create_start_index_too_large_error,
2525
)
26-
from nitypes.waveform._extended_properties import (
27-
CHANNEL_NAME,
28-
UNIT_DESCRIPTION,
29-
ExtendedPropertyDictionary,
30-
ExtendedPropertyValue,
31-
)
32-
from nitypes.waveform._scaling import NO_SCALING, ScaleMode
33-
from nitypes.waveform._timing import Timing, _AnyDateTime, _AnyTimeDelta
26+
from nitypes.waveform._extended_properties import CHANNEL_NAME, UNIT_DESCRIPTION
27+
from nitypes.waveform._timing import _AnyDateTime, _AnyTimeDelta
3428
from nitypes.waveform._warnings import scale_mode_mismatch
3529

3630
if sys.version_info < (3, 10):
3731
import array as std_array
3832

33+
if TYPE_CHECKING:
34+
# Import from the public package so the docs don't reference private submodules.
35+
from nitypes.waveform import (
36+
NO_SCALING,
37+
ExtendedPropertyDictionary,
38+
ExtendedPropertyValue,
39+
ScaleMode,
40+
Timing,
41+
)
42+
else:
43+
from nitypes.waveform._extended_properties import (
44+
ExtendedPropertyDictionary,
45+
ExtendedPropertyValue,
46+
)
47+
from nitypes.waveform._scaling import NO_SCALING, ScaleMode
48+
from nitypes.waveform._timing import Timing
49+
3950
# _TRaw specifies the type of the raw_data array. It is not limited to supported types. Requesting
4051
# an unsupported type raises TypeError at run time. It is invariant because waveforms are mutable.
4152
_TRaw = TypeVar("_TRaw", bound=np.generic)

src/nitypes/waveform/_scaling/_linear.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,17 @@
11
from __future__ import annotations
22

3-
from typing import SupportsFloat
3+
from typing import TYPE_CHECKING, SupportsFloat
44

55
import numpy.typing as npt
66

77
from nitypes._arguments import arg_to_float
8-
from nitypes.waveform._scaling._base import ScaleMode, _ScalarType
8+
from nitypes.waveform._scaling._base import _ScalarType
9+
10+
if TYPE_CHECKING:
11+
# Import from the public package so the docs don't reference private submodules.
12+
from nitypes.waveform import ScaleMode
13+
else:
14+
from nitypes.waveform._scaling._base import ScaleMode
915

1016

1117
class LinearScaleMode(ScaleMode):

0 commit comments

Comments
 (0)