Skip to content

Commit a292757

Browse files
committed
removed all string type hints and replaced with forward references (not supported in Python 3.6)
1 parent 602575d commit a292757

1 file changed

Lines changed: 23 additions & 47 deletions

File tree

scadnano/scadnano.py

Lines changed: 23 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1023,7 +1023,7 @@ def to_json_serializable(self, suppress_indent: bool = True, **kwargs: Any) -> D
10231023

10241024
@staticmethod
10251025
def from_json(
1026-
json_map: Dict[str, Any]) -> 'Modification': # remove quotes when Py3.6 support dropped
1026+
json_map: Dict[str, Any]) -> Modification:
10271027
location = json_map[mod_location_key]
10281028
if location == "5'":
10291029
return Modification5Prime.from_json(json_map)
@@ -1061,9 +1061,8 @@ def to_json_serializable(self, suppress_indent: bool = True, **kwargs: Any) -> D
10611061
ret[mod_location_key] = "5'"
10621062
return ret
10631063

1064-
# remove quotes when Py3.6 support dropped
10651064
@staticmethod
1066-
def from_json(json_map: Dict[str, Any]) -> 'Modification5Prime':
1065+
def from_json(json_map: Dict[str, Any]) -> Modification5Prime:
10671066
display_text = json_map[mod_display_text_key]
10681067
location = json_map[mod_location_key]
10691068
assert location == "5'"
@@ -1098,9 +1097,8 @@ def to_json_serializable(self, suppress_indent: bool = True, **kwargs: Any) -> D
10981097
ret[mod_location_key] = "3'"
10991098
return ret
11001099

1101-
# remove quotes when Py3.6 support dropped
11021100
@staticmethod
1103-
def from_json(json_map: Dict[str, Any]) -> 'Modification3Prime':
1101+
def from_json(json_map: Dict[str, Any]) -> Modification3Prime:
11041102
display_text = json_map[mod_display_text_key]
11051103
location = json_map[mod_location_key]
11061104
assert location == "3'"
@@ -1138,9 +1136,8 @@ def to_json_serializable(self, suppress_indent: bool = True, **kwargs: Any) -> D
11381136
list(self.allowed_bases)) if suppress_indent else list(self.allowed_bases)
11391137
return ret
11401138

1141-
# remove quotes when Py3.6 support dropped
11421139
@staticmethod
1143-
def from_json(json_map: Dict[str, Any]) -> 'ModificationInternal':
1140+
def from_json(json_map: Dict[str, Any]) -> ModificationInternal:
11441141
display_text = json_map[mod_display_text_key]
11451142
location = json_map[mod_location_key]
11461143
assert location == "internal"
@@ -1186,7 +1183,7 @@ def to_json_serializable(self, suppress_indent: bool = True, **kwargs: Any) -> D
11861183
return dct
11871184

11881185
@staticmethod
1189-
def from_json(json_map: Dict[str, Any]) -> 'Position3D': # remove quotes when Py3.6 support dropped
1186+
def from_json(json_map: Dict[str, Any]) -> Position3D:
11901187
if position_origin_key in json_map:
11911188
origin_ = json_map[position_origin_key]
11921189
x = origin_[position_x_key]
@@ -1317,7 +1314,7 @@ def _assign_default_helices_view_order(self, helices_in_group: Dict[int, 'Helix'
13171314
self.helices_view_order = _check_helices_view_order_and_return(self.helices_view_order, helix_idxs)
13181315

13191316
@staticmethod
1320-
def from_json(json_map: dict, **kwargs: Any) -> 'HelixGroup': # remove quotes when Py3.6 support dropped
1317+
def from_json(json_map: dict, **kwargs: Any) -> HelixGroup:
13211318
grid: Grid = optional_field(Grid.none, json_map, grid_key, transformer=Grid)
13221319
# grid: Grid = Grid.none
13231320
# if grid_key in json_map:
@@ -1398,7 +1395,7 @@ def is_default(self) -> bool:
13981395
return self == _default_geometry
13991396

14001397
@staticmethod
1401-
def from_json(json_map: dict) -> 'Geometry': # remove quotes when Py3.6 support dropped
1398+
def from_json(json_map: dict) -> Geometry:
14021399
geometry = Geometry()
14031400
geometry.rise_per_base_pair = optional_field(_default_geometry.rise_per_base_pair, json_map,
14041401
rise_per_base_pair_key,
@@ -1621,7 +1618,7 @@ def to_json_serializable(self, suppress_indent: bool = True, **kwargs: Any) -> D
16211618
return NoIndent(dct) if suppress_indent and use_no_indent_helix else dct
16221619

16231620
@staticmethod
1624-
def from_json(json_map: dict) -> 'Helix': # remove quotes when Py3.6 support dropped
1621+
def from_json(json_map: dict) -> Helix:
16251622
grid_position: Optional[Tuple[int, int]] = None
16261623
if grid_position_key in json_map:
16271624
gp_list = json_map[grid_position_key]
@@ -1815,7 +1812,7 @@ class Domain(_JSONSerializable):
18151812
"""
18161813

18171814
# not serialized; for efficiency
1818-
# remove quotes when Py3.6 support dropped
1815+
18191816
_parent_strand: Optional[Strand] = field(init=False, repr=False, compare=False, default=None)
18201817

18211818
def __post_init__(self) -> None:
@@ -1841,7 +1838,7 @@ def to_json_serializable(self, suppress_indent: bool = True,
18411838
return NoIndent(dct) if suppress_indent else dct
18421839

18431840
@staticmethod
1844-
def from_json(json_map: Dict[str, Any]) -> Domain: # remove quotes when Py3.6 support dropped
1841+
def from_json(json_map: Dict[str, Any]) -> Domain:
18451842
helix = mandatory_field(Domain, json_map, helix_idx_key)
18461843
forward = mandatory_field(Domain, json_map, forward_key, legacy_keys=legacy_forward_keys)
18471844
start = mandatory_field(Domain, json_map, start_key)
@@ -1881,7 +1878,7 @@ def __repr__(self) -> str:
18811878
def __str__(self) -> str:
18821879
return repr(self) if self.name is None else self.name
18831880

1884-
def strand(self) -> Strand: # remove quotes when Py3.6 support dropped
1881+
def strand(self) -> Strand:
18851882
"""
18861883
:return: The :any:`Strand` that contains this :any:`Domain`.
18871884
"""
@@ -2090,7 +2087,6 @@ def overlaps(self, other: Domain) -> bool:
20902087
return (self.forward == (not other.forward) and
20912088
self.compute_overlap(other)[0] >= 0)
20922089

2093-
# remove quotes when Py3.6 support dropped
20942090
# def overlaps_illegally(self, other: Domain):
20952091
def overlaps_illegally(self, other: Domain) -> bool:
20962092
r"""Indicates if this :any:`Domain`'s set of offsets (the set
@@ -2105,8 +2101,6 @@ def overlaps_illegally(self, other: Domain) -> bool:
21052101
return (self.forward == other.forward and
21062102
self.compute_overlap(other)[0] >= 0)
21072103

2108-
# remove quotes when Py3.6 support dropped
2109-
# def compute_overlap(self, other: Domain) -> Tuple[int, int]:
21102104
def compute_overlap(self, other: Domain) -> Tuple[int, int]:
21112105
"""Return [left,right) offset indicating overlap between this Domain and `other`.
21122106
@@ -2216,7 +2210,7 @@ class Loopout(_JSONSerializable):
22162210
"""
22172211

22182212
# not serialized; for efficiency
2219-
# remove quotes when Py3.6 support dropped
2213+
22202214
_parent_strand: Optional[Strand] = field(init=False, repr=False, compare=False, default=None)
22212215

22222216
def to_json_serializable(self, suppress_indent: bool = True,
@@ -2231,7 +2225,7 @@ def to_json_serializable(self, suppress_indent: bool = True,
22312225
return NoIndent(dct) if suppress_indent else dct
22322226

22332227
@staticmethod
2234-
def from_json(json_map: Dict[str, Any]) -> 'Loopout': # remove quotes when Py3.6 support dropped
2228+
def from_json(json_map: Dict[str, Any]) -> Loopout:
22352229
# XXX: this should never fail since we detect whether to call this from_json by the presence
22362230
# of a length key in json_map
22372231
length_str = mandatory_field(Loopout, json_map, loopout_key)
@@ -2242,7 +2236,7 @@ def from_json(json_map: Dict[str, Any]) -> 'Loopout': # remove quotes when Py3.
22422236
color = Color.from_json(color_json)
22432237
return Loopout(length=length, name=name, label=label, color=color)
22442238

2245-
def strand(self) -> Strand: # remove quotes when Py3.6 support dropped
2239+
def strand(self) -> Strand:
22462240
"""
22472241
:return: The :any:`Strand` that contains this :any:`Loopout`.
22482242
"""
@@ -2378,7 +2372,7 @@ class Extension(_JSONSerializable):
23782372
"""
23792373

23802374
# not serialized; for efficiency
2381-
# remove quotes when Py3.6 support dropped
2375+
23822376
_parent_strand: Optional[Strand] = field(init=False, repr=False, compare=False, default=None)
23832377

23842378
def to_json_serializable(self, suppress_indent: bool = True, **kwargs: Any) \
@@ -2577,7 +2571,6 @@ def strand(self) -> Strand:
25772571
raise ValueError('no Strand created yet; make at least one domain first')
25782572
return self._strand
25792573

2580-
# remove quotes when Py3.6 support dropped
25812574
def cross(self, helix: int, offset: Optional[int] = None, move: Optional[int] = None) \
25822575
-> StrandBuilder:
25832576
"""
@@ -2616,7 +2609,6 @@ def _most_recently_added_substrand_is_instance_of_class(self, cls: Type) -> bool
26162609
def _most_recently_added_substrand_is_extension(self):
26172610
return self._most_recently_added_substrand_is_instance_of_class(Extension)
26182611

2619-
# remove quotes when Py3.6 support dropped
26202612
def loopout(self, helix: int, length: int, offset: Optional[int] = None, move: Optional[int] = None) \
26212613
-> StrandBuilder:
26222614
"""
@@ -2706,7 +2698,6 @@ def _verify_extension_5p_is_valid(self):
27062698
'Cannot add a 5\' extension when there are already domains. '
27072699
'Did you mean to create a 3\' extension?')
27082700

2709-
# remove quotes when Py3.6 support dropped
27102701
def move(self, delta: int) -> StrandBuilder:
27112702
"""
27122703
Extends this :any:`StrandBuilder` on the current helix to offset given by the current offset
@@ -2729,7 +2720,6 @@ def move(self, delta: int) -> StrandBuilder:
27292720
"""
27302721
return self.to(self.current_offset + delta)
27312722

2732-
# remove quotes when Py3.6 support dropped
27332723
def to(self, offset: int) -> StrandBuilder:
27342724
"""
27352725
Extends this :any:`StrandBuilder` on the current helix to offset `offset`,
@@ -2791,7 +2781,6 @@ def _most_recently_added_substrand_is_extension_3p(self) -> bool:
27912781
return False
27922782
return len(self._strand.domains) > 1 and self._most_recently_added_substrand_is_extension()
27932783

2794-
# remove quotes when Py3.6 support dropped
27952784
def update_to(self, offset: int) -> StrandBuilder:
27962785
"""
27972786
Like :py:meth:`StrandBuilder.to`, but changes the current offset without creating
@@ -2839,7 +2828,6 @@ def as_circular(self) -> StrandBuilder:
28392828
self._strand.set_circular()
28402829
return self
28412830

2842-
# remove quotes when Py3.6 support dropped
28432831
def as_scaffold(self) -> StrandBuilder:
28442832
"""
28452833
Makes :any:`Strand` being built a scaffold.
@@ -2875,7 +2863,6 @@ def with_idt(self, scale: str = default_idt_scale,
28752863
plate=plate, well=well)
28762864
return self
28772865

2878-
# remove quotes when Py3.6 support dropped
28792866
def with_modification_5p(self, mod: Modification5Prime) -> StrandBuilder:
28802867
"""
28812868
Sets Strand being built to have given 5' modification.
@@ -2888,7 +2875,6 @@ def with_modification_5p(self, mod: Modification5Prime) -> StrandBuilder:
28882875
self._strand.set_modification_5p(mod)
28892876
return self
28902877

2891-
# remove quotes when Py3.6 support dropped
28922878
def with_modification_3p(self, mod: Modification3Prime) -> StrandBuilder:
28932879
"""
28942880
Sets Strand being built to have given 3' modification.
@@ -2901,7 +2887,6 @@ def with_modification_3p(self, mod: Modification3Prime) -> StrandBuilder:
29012887
self._strand.set_modification_3p(mod)
29022888
return self
29032889

2904-
# remove quotes when Py3.6 support dropped
29052890
def with_modification_internal(self, idx: int, mod: ModificationInternal, warn_on_no_dna: bool) \
29062891
-> StrandBuilder:
29072892
"""
@@ -2917,7 +2902,6 @@ def with_modification_internal(self, idx: int, mod: ModificationInternal, warn_o
29172902
self._strand.set_modification_internal(idx, mod, warn_on_no_dna)
29182903
return self
29192904

2920-
# remove quotes when Py3.6 support dropped
29212905
def with_color(self, color: Color) -> StrandBuilder:
29222906
"""
29232907
Sets Strand being built to have given color.
@@ -2930,7 +2914,6 @@ def with_color(self, color: Color) -> StrandBuilder:
29302914
self._strand.set_color(color)
29312915
return self
29322916

2933-
# remove quotes when Py3.6 support dropped
29342917
def with_sequence(self, sequence: str, assign_complement: bool = False) \
29352918
-> StrandBuilder:
29362919
"""
@@ -2952,7 +2935,6 @@ def with_sequence(self, sequence: str, assign_complement: bool = False) \
29522935
self.design.assign_dna(strand=self._strand, sequence=sequence, assign_complement=assign_complement)
29532936
return self
29542937

2955-
# remove quotes when Py3.6 support dropped
29562938
def with_domain_sequence(self, sequence: str, assign_complement: bool = False) \
29572939
-> StrandBuilder:
29582940
"""
@@ -2990,7 +2972,6 @@ def with_domain_sequence(self, sequence: str, assign_complement: bool = False) \
29902972
assign_complement=assign_complement)
29912973
return self
29922974

2993-
# remove quotes when Py3.6 support dropped
29942975
def with_domain_color(self, color: Color) -> StrandBuilder:
29952976
"""
29962977
Sets most recent :any:`Domain`/:any:`Loopout`/:any:`Extension`
@@ -3007,7 +2988,6 @@ def with_domain_color(self, color: Color) -> StrandBuilder:
30072988
last_domain.color = color
30082989
return self
30092990

3010-
# remove quotes when Py3.6 support dropped
30112991
def with_name(self, name: str) -> StrandBuilder:
30122992
"""
30132993
Assigns `name` as name of the :any:`Strand` being built.
@@ -3024,7 +3004,6 @@ def with_name(self, name: str) -> StrandBuilder:
30243004
self._strand.set_name(name)
30253005
return self
30263006

3027-
# remove quotes when Py3.6 support dropped
30283007
def with_label(self, label: str) -> StrandBuilder:
30293008
"""
30303009
Assigns `label` as label of the :any:`Strand` being built.
@@ -3041,7 +3020,6 @@ def with_label(self, label: str) -> StrandBuilder:
30413020
self._strand.set_label(label)
30423021
return self
30433022

3044-
# remove quotes when Py3.6 support dropped
30453023
def with_domain_name(self, name: str) -> StrandBuilder:
30463024
"""
30473025
Assigns `name` as of the most recently created :any:`Domain` or :any:`Loopout` in
@@ -3066,7 +3044,6 @@ def with_domain_name(self, name: str) -> StrandBuilder:
30663044
last_domain.set_name(name)
30673045
return self
30683046

3069-
# remove quotes when Py3.6 support dropped
30703047
def with_domain_label(self, label: str) -> StrandBuilder:
30713048
"""
30723049
Assigns `label` as label of the most recently created :any:`Domain` or :any:`Loopout` in
@@ -3402,12 +3379,12 @@ def to_json_serializable(self, suppress_indent: bool = True, **kwargs: Any) -> D
34023379
dct[modifications_int_key] = NoIndent(mods_dict) if suppress_indent else mods_dict
34033380

34043381
if self.label is not None:
3405-
dct[strand_label_key] = NoIndent(self.label) if suppress_indent else self.label
3382+
dct[strand_label_key] = self.label
34063383

34073384
return dct
34083385

34093386
@staticmethod
3410-
def from_json(json_map: dict) -> Strand: # remove quotes when Py3.6 support dropped
3387+
def from_json(json_map: dict) -> Strand:
34113388
substrand_jsons = mandatory_field(Strand, json_map, domains_key, legacy_keys=legacy_domains_keys)
34123389
if len(substrand_jsons) == 0:
34133390
raise IllegalDesignError(f'{domains_key} list cannot be empty')
@@ -3465,7 +3442,7 @@ def from_json(json_map: dict) -> Strand: # remove quotes when Py3.6 support dro
34653442
label=label,
34663443
)
34673444

3468-
def __eq__(self, other: Any) -> bool: # remove quotes when Py3.6 support dropped
3445+
def __eq__(self, other: Any) -> bool:
34693446
if not isinstance(other, Strand):
34703447
return False
34713448
return self.domains == other.domains
@@ -3751,7 +3728,7 @@ def offset_3p(self) -> int:
37513728
"""3' offset of this entire :any:`Strand`, INCLUSIVE."""
37523729
return self.last_domain().offset_3p()
37533730

3754-
def overlaps(self, other: Strand) -> bool: # remove quotes when Py3.6 support dropped
3731+
def overlaps(self, other: Strand) -> bool:
37553732
"""Indicates whether `self` overlaps `other_strand`, meaning that the set of offsets occupied
37563733
by `self` has nonempty intersection with those occupied by `other_strand`."""
37573734
for domain_self in self.bound_domains():
@@ -3760,7 +3737,7 @@ def overlaps(self, other: Strand) -> bool: # remove quotes when Py3.6 support d
37603737
return True
37613738
return False
37623739

3763-
def assign_dna_complement_from(self, other: Strand) -> None: # remove quotes when Py3.6 support dropped
3740+
def assign_dna_complement_from(self, other: Strand) -> None:
37643741
"""Assuming a DNA sequence has been assigned to `other`, assign its Watson-Crick
37653742
complement to the portions of this Strand that are bound to `other`.
37663743
@@ -5186,7 +5163,7 @@ def roll_of_helix(self, helix: Helix) -> float:
51865163
return self.groups[helix.group].roll + helix.roll
51875164

51885165
@staticmethod
5189-
def from_scadnano_file(filename: str) -> 'Design': # remove quotes when Py3.6 support dropped
5166+
def from_scadnano_file(filename: str) -> Design:
51905167
"""
51915168
Loads a :any:`Design` from the file with the given name.
51925169
@@ -5198,7 +5175,7 @@ def from_scadnano_file(filename: str) -> 'Design': # remove quotes when Py3.6 s
51985175
return Design.from_scadnano_json_str(json_str)
51995176

52005177
@staticmethod
5201-
def from_scadnano_json_str(json_str: str) -> 'Design': # remove quotes when Py3.6 support dropped
5178+
def from_scadnano_json_str(json_str: str) -> Design:
52025179
"""
52035180
Loads a :any:`Design` from the given JSON string.
52045181
@@ -5406,7 +5383,7 @@ def _helices_and_groups_and_grid_from_json(json_map: Dict) \
54065383

54075384
@staticmethod
54085385
def from_scadnano_json_map(
5409-
json_map: dict) -> 'Design': # remove quotes when Py3.6 support dropped
5386+
json_map: dict) -> Design:
54105387
"""
54115388
Loads a :any:`Design` from the given JSON object (i.e., Python object obtained by calling
54125389
json.loads(json_str) from a string representing contents of a JSON file.
@@ -5796,7 +5773,6 @@ def _cadnano_v2_import_explore_strand(vstrands: VStrands,
57965773

57975774
return strand
57985775

5799-
# remove quotes when Py3.6 support dropped
58005776
@staticmethod
58015777
def from_cadnano_v2(directory: str = '', filename: Optional[str] = None,
58025778
json_dict: Optional[dict] = None) -> 'Design':

0 commit comments

Comments
 (0)