Skip to content

Commit 3c24e2d

Browse files
hyanwongmergify[bot]
authored andcommitted
Auto show return types in docs
Requires us to document a few classes that should be public anyway, as they are returned from public functions.
1 parent b07b3e2 commit 3c24e2d

File tree

7 files changed

+73
-21
lines changed

7 files changed

+73
-21
lines changed

docs/_config.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ sphinx:
3131
extra_extensions:
3232
- breathe
3333
- sphinx.ext.autodoc
34+
- sphinx_autodoc_typehints
3435
- sphinx.ext.autosummary
3536
- sphinx.ext.todo
3637
- sphinx.ext.viewcode

docs/python-api.md

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1477,7 +1477,6 @@ section for more details and examples.
14771477

14781478
#### The {class}`ReferenceSequence` class
14791479

1480-
14811480
```{eval-rst}
14821481
.. todo:: Add a top-level summary section that we can link to from here.
14831482
```
@@ -1498,6 +1497,13 @@ Also see the {ref}`sec_python_api_metadata` summary.
14981497
:inherited-members:
14991498
```
15001499

1500+
#### The {class}`TableMetadataSchemas` class
1501+
1502+
```{eval-rst}
1503+
.. autoclass:: TableMetadataSchemas
1504+
:members:
1505+
```
1506+
15011507
#### The {class}`TopologyCounter` class
15021508

15031509
```{eval-rst}
@@ -1511,7 +1517,15 @@ Also see the {ref}`sec_python_api_metadata` summary.
15111517
:members:
15121518
```
15131519

1520+
#### The {class}`TableCollectionIndexes` class
1521+
1522+
```{eval-rst}
1523+
.. autoclass:: TableCollectionIndexes
1524+
:members:
1525+
```
1526+
15141527
#### The {class}`SVGString` class
1528+
15151529
```{eval-rst}
15161530
.. autoclass:: SVGString
15171531
:members:

python/requirements/CI-docs/requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ numpy==1.22.3
88
PyGithub==1.55
99
sphinx==4.5.0
1010
sphinx-argparse==0.3.1
11+
sphinx-autodoc-typehints==1.18.3
1112
sphinx-issues==3.0.1
1213
sphinxcontrib-prettyspecialmethods==0.1.0
1314
svgwrite==1.4.2

python/requirements/development.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ pytest-cov
2727
pytest-xdist
2828
sphinx==4.5
2929
sphinx-argparse
30+
sphinx-autodoc-typehints
3031
sphinx-issues
3132
sphinx-jupyterbook-latex
3233
sphinxcontrib-prettyspecialmethods

python/tskit/genotypes.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,7 @@ def decode(self, site_id) -> None:
207207
"""
208208
Decode the variant at the given site, setting the site ID, genotypes and
209209
alleles to those of the site and samples of this Variant.
210+
210211
:param int site_id: The ID of the site to decode. This must be a valid site ID.
211212
"""
212213
self._ll_variant.decode(site_id)
@@ -215,6 +216,7 @@ def copy(self) -> Variant:
215216
"""
216217
Create a copy of this Variant. Note that calling :meth:`decode` on the
217218
copy will fail as it does not take a copy of the internal tree.
219+
218220
:return: The copy of this Variant.
219221
"""
220222
variant_copy = Variant.__new__(Variant)

python/tskit/tables.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -301,14 +301,21 @@ class ProvenanceTableRow(util.Dataclass):
301301

302302
@dataclass(**dataclass_options)
303303
class TableCollectionIndexes(util.Dataclass):
304+
"""
305+
A class encapsulating the indexes of a :class:`TableCollection`
306+
"""
307+
304308
edge_insertion_order: np.ndarray = None
305309
edge_removal_order: np.ndarray = None
306310

307311
def asdict(self):
308312
return {k: v for k, v in dataclasses.asdict(self).items() if v is not None}
309313

310314
@property
311-
def nbytes(self):
315+
def nbytes(self) -> int:
316+
"""
317+
The number of bytes taken by the indexes
318+
"""
312319
total = 0
313320
if self.edge_removal_order is not None:
314321
total += self.edge_removal_order.nbytes

python/tskit/trees.py

Lines changed: 45 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3800,6 +3800,48 @@ def __getitem__(self, index):
38003800
return self.getter(index)
38013801

38023802

3803+
@dataclass(frozen=True)
3804+
class TableMetadataSchemas:
3805+
"""
3806+
Convenience class for returning the schemas of all the tables in a tree sequence.
3807+
"""
3808+
3809+
node: metadata_module.MetadataSchema = None
3810+
"""
3811+
The metadata schema of the node table.
3812+
"""
3813+
3814+
edge: metadata_module.MetadataSchema = None
3815+
"""
3816+
The metadata schema of the edge table.
3817+
"""
3818+
3819+
site: metadata_module.MetadataSchema = None
3820+
"""
3821+
The metadata schema of the site table.
3822+
"""
3823+
3824+
mutation: metadata_module.MetadataSchema = None
3825+
"""
3826+
The metadata schema of the mutation table.
3827+
"""
3828+
3829+
migration: metadata_module.MetadataSchema = None
3830+
"""
3831+
The metadata schema of the migration table.
3832+
"""
3833+
3834+
individual: metadata_module.MetadataSchema = None
3835+
"""
3836+
The metadata schema of the individual table.
3837+
"""
3838+
3839+
population: metadata_module.MetadataSchema = None
3840+
"""
3841+
The metadata schema of the population table.
3842+
"""
3843+
3844+
38033845
class TreeSequence:
38043846
"""
38053847
A single tree sequence, as defined by the :ref:`data model <sec_data_model>`.
@@ -3819,33 +3861,17 @@ class TreeSequence:
38193861
the :meth:`.variants` method iterates over all sites and their genotypes.
38203862
"""
38213863

3822-
@dataclass(frozen=True)
3823-
class _TableMetadataSchemas:
3824-
"""
3825-
Convenience class for returning schemas
3826-
"""
3827-
3828-
node: metadata_module.MetadataSchema = None
3829-
edge: metadata_module.MetadataSchema = None
3830-
site: metadata_module.MetadataSchema = None
3831-
mutation: metadata_module.MetadataSchema = None
3832-
migration: metadata_module.MetadataSchema = None
3833-
individual: metadata_module.MetadataSchema = None
3834-
population: metadata_module.MetadataSchema = None
3835-
38363864
def __init__(self, ll_tree_sequence):
38373865
self._ll_tree_sequence = ll_tree_sequence
38383866
metadata_schema_strings = self._ll_tree_sequence.get_table_metadata_schemas()
38393867
metadata_schema_instances = {
38403868
name: metadata_module.parse_metadata_schema(
38413869
getattr(metadata_schema_strings, name)
38423870
)
3843-
for name in vars(self._TableMetadataSchemas)
3871+
for name in vars(TableMetadataSchemas)
38443872
if not name.startswith("_")
38453873
}
3846-
self._table_metadata_schemas = self._TableMetadataSchemas(
3847-
**metadata_schema_instances
3848-
)
3874+
self._table_metadata_schemas = TableMetadataSchemas(**metadata_schema_instances)
38493875
self._individuals_time = None
38503876
self._individuals_population = None
38513877
self._individuals_location = None
@@ -4134,7 +4160,7 @@ def num_samples(self):
41344160
return self._ll_tree_sequence.get_num_samples()
41354161

41364162
@property
4137-
def table_metadata_schemas(self) -> _TableMetadataSchemas:
4163+
def table_metadata_schemas(self) -> TableMetadataSchemas:
41384164
"""
41394165
The set of metadata schemas for the tables in this tree sequence.
41404166
"""

0 commit comments

Comments
 (0)