Skip to content

Commit 42424f3

Browse files
committed
feat(utils): improve type hints, docs
1 parent 91269db commit 42424f3

File tree

1 file changed

+39
-3
lines changed

1 file changed

+39
-3
lines changed

neuroml/utils.py

Lines changed: 39 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,20 @@
1515
import networkx
1616

1717
import neuroml.nml.nml as schema
18-
from neuroml import BiophysicalProperties, Morphology, NeuroMLDocument
18+
from neuroml import (
19+
BiophysicalProperties,
20+
GateFractional,
21+
GateHHInstantaneous,
22+
GateHHRates,
23+
GateHHRatesInf,
24+
GateHHRatesTau,
25+
GateHHRatesTauInf,
26+
GateHHTauInf,
27+
GateHHUndetermined,
28+
GateKS,
29+
Morphology,
30+
NeuroMLDocument,
31+
)
1932

2033
from . import loaders
2134

@@ -472,10 +485,24 @@ def fix_external_morphs_biophys_in_cell(
472485
return newdoc
473486

474487

475-
def create_new_typed_gate(gate):
488+
def create_new_typed_gate(
489+
gate: GateHHUndetermined,
490+
) -> Optional[
491+
Union[
492+
GateHHRates,
493+
GateHHRatesTau,
494+
GateHHRatesInf,
495+
GateHHRatesTauInf,
496+
GateHHTauInf,
497+
GateHHInstantaneous,
498+
GateFractional,
499+
GateKS,
500+
]
501+
]:
476502
"""Convert an undetermined gate to a "determined" gate
477503
478504
:param gate: gate object of GateHHUndetermined type
505+
:type gate: GateHHUndetermined
479506
:returns: new gate object, or None if the gate is not of a standard type
480507
"""
481508
gates_name_map = {
@@ -501,17 +528,26 @@ def create_new_typed_gate(gate):
501528
new_gate.__dict__.update(gate.__dict__)
502529
return new_gate
503530

531+
return None
504532

505-
def move_undetermined_gates_to_typed(nml2_doc):
533+
534+
def move_undetermined_gates_to_typed(nml2_doc: NeuroMLDocument):
506535
"""Replace gates of GateHHUndetermined type with their standard
507536
counterparts where possible.
508537
509538
Note that this modifies the passed NeuroMLDocument object in-place.
510539
540+
If `nml2_doc` is not a NeuroMLDocument, this function does nothing and
541+
simply returns None.
542+
511543
:param nml2_doc: NeuroMLDocument object
544+
:type nml2_doc: NeuroMLDocument
512545
:returns: None
513546
514547
"""
548+
if not isinstance(nml2_doc, NeuroMLDocument):
549+
return None
550+
515551
all_channels = (
516552
list(nml2_doc.ion_channel_hhs.__iter__())
517553
+ list(nml2_doc.ion_channel.__iter__())

0 commit comments

Comments
 (0)