Skip to content

Commit bd315fd

Browse files
committed
Fix numerous flake highlighted issues (== -> is etc)
1 parent fd97461 commit bd315fd

File tree

7 files changed

+30
-35
lines changed

7 files changed

+30
-35
lines changed

.github/workflows/ci.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ jobs:
1414
steps:
1515
- uses: actions/checkout@v4
1616
- uses: actions/setup-python@v5
17+
with:
18+
python-version: "3.10"
1719
- uses: pre-commit/[email protected]
1820
with:
1921
extra_args: --hook-stage manual --all-files

docs/sphinx/source/api/examples/document.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
from modelspec.base_types import Base
44
from typing import List
55
import sys
6+
import json
7+
import yaml
8+
import bson
69

710
# Example showing how to create a model of a document and use it to create/serialize instances
811

@@ -96,9 +99,6 @@ class Document(Base):
9699
print("\n >> Generating specification in dict form...")
97100
doc_dict = doc.generate_documentation(format="dict")
98101

99-
import json
100-
import yaml
101-
import bson
102102

103103
with open("document.specification.json", "w") as d:
104104
d.write(json.dumps(doc_dict, indent=4))

examples/document.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
from modelspec.base_types import Base
44
from typing import List
55
import sys
6+
import json
7+
import yaml
8+
import bson
69

710
# Example showing how to create a model of a document and use it to create/serialize instances
811

@@ -96,9 +99,6 @@ class Document(Base):
9699
print("\n >> Generating specification in dict form...")
97100
doc_dict = doc.generate_documentation(format="dict")
98101

99-
import json
100-
import yaml
101-
import bson
102102

103103
with open("document.specification.json", "w") as d:
104104
d.write(json.dumps(doc_dict, indent=4))

examples/test/test.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
import modelspec
22
from modelspec import field, instance_of, optional
33
from modelspec.base_types import Base
4-
from modelspec.utils import load_json
5-
from typing import List
64
from typing import Any
75
import sys
6+
import yaml
87

98

109
# Example testing multiple options...
@@ -104,7 +103,6 @@ class TopClass(Base):
104103
print("\nGenerating specification in dict form")
105104
doc_dict = tc.generate_documentation(format="dict")
106105

107-
import yaml
108106

109107
print("Generating specification in YAML")
110108
with open("test.specification.yaml", "w") as d:

src/modelspec/base_types.py

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -169,18 +169,13 @@ def from_yaml(cls, yaml_str: str) -> "Base":
169169
@classmethod
170170
def from_yaml_file(cls, yaml_file: str) -> "Base":
171171
"""Instantiate an modelspec object from a file containing YAML"""
172-
return cls.from_dict(yaml.load(yaml_str, Loader=yaml.SafeLoader))
172+
return cls.from_dict(yaml.load(yaml_file, Loader=yaml.SafeLoader))
173173

174174
@classmethod
175175
def from_json(cls, json_str: str) -> "Base":
176176
"""Instantiate an modelspec object from a JSON string"""
177177
return cls.from_dict(json.loads(json_str))
178178

179-
@classmethod
180-
def from_json_file(cls, json_file: str) -> "Base":
181-
"""Instantiate an modelspec object from a file containing JSON"""
182-
return cls.from_dict(json.load(json_file))
183-
184179
@classmethod
185180
def from_bson(cls, bson_str: str) -> "Base":
186181
"""Instantiate an modelspec object from a BSON string"""
@@ -318,7 +313,6 @@ def to_xml_file(
318313
filename: Optional[str] = None,
319314
include_metadata: bool = True,
320315
) -> str:
321-
from modelspec.utils import build_xml_element
322316

323317
if filename is None:
324318
filename = f"{self.id}.xml"

src/modelspec/utils.py

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
from modelspec.base_types import EvaluableExpression
1515

1616
from random import Random
17-
from typing import Union, Dict
17+
from typing import Union
1818

1919
verbose = False
2020

@@ -272,11 +272,11 @@ def build_xml_element(data, parent=None):
272272
)
273273
if attribute_value is not None:
274274
if (
275-
type(attribute_value) == int
276-
or type(attribute_value) == float
277-
or type(attribute_value) == str
278-
or type(attribute_value) == bool
279-
or type(attribute_value) == list
275+
type(attribute_value) is int
276+
or type(attribute_value) is float
277+
or type(attribute_value) is str
278+
or type(attribute_value) is bool
279+
or type(attribute_value) is list
280280
):
281281
parent.set(attribute_name, str(attribute_value))
282282
elif type(attribute_value) == dict:
@@ -411,15 +411,15 @@ def _val_info(param_val):
411411
pp = "%s" % param_val
412412
pp = pp.replace("\n", "")
413413
# pp+=' (TF %s %s)'%(param_val.shape,param_val.dtype)
414-
elif type(param_val) == tuple:
414+
elif type(param_val) is tuple:
415415
# If param_val is a tuple, recursively print its elements
416416
# separated by commas and wrapped in parentheses
417417
pp = "(" + ", ".join([_val_info(el) for el in param_val]) + ")"
418418
else:
419419
pp = "%s" % param_val
420420
t = type(param_val)
421-
if not (t == int or t == float):
422-
pp += "(%s)" % (t if type(t) == str else t.__name__)
421+
if not (t is int or t is float):
422+
pp += "(%s)" % (t if type(t) is str else t.__name__)
423423
return pp
424424

425425

@@ -476,13 +476,13 @@ def evaluate(
476476
verbose,
477477
)
478478
try:
479-
if type(expr) == str and expr in parameters:
479+
if type(expr) is str and expr in parameters:
480480
expr = parameters[
481481
expr
482482
] # replace with the value in parameters & check whether it's float/int...
483483
print_(" Using for that param: %s" % _val_info(expr), verbose)
484484

485-
if type(expr) == str:
485+
if type(expr) is str:
486486
try:
487487
if array_format == FORMAT_TENSORFLOW:
488488
expr = tf.constant(int(expr))
@@ -498,14 +498,14 @@ def evaluate(
498498
except:
499499
pass
500500

501-
if type(expr) == list:
501+
if type(expr) is list:
502502
print_(" Returning a list in format: %s" % array_format, verbose)
503503
if array_format == FORMAT_TENSORFLOW:
504504
return tf.constant(expr, dtype=tf.float64)
505505
else:
506506
return np.array(expr)
507507

508-
if type(expr) == np.ndarray:
508+
if type(expr) is np.ndarray:
509509
print_(" Returning a numpy array in format: %s" % array_format, verbose)
510510
if array_format == FORMAT_TENSORFLOW:
511511
return tf.convert_to_tensor(expr, dtype=tf.float64)
@@ -538,9 +538,9 @@ def evaluate(
538538
"The expression [%s] contains a random() call, but a random number generator (rng) must be supplied to the evaluate() call when this expression string is to be evaluated"
539539
)
540540

541-
if type(expr) == str and "math." in expr:
541+
if type(expr) is str and "math." in expr:
542542
parameters["math"] = math
543-
if type(expr) == str and "numpy." in expr:
543+
if type(expr) is str and "numpy." in expr:
544544
parameters["numpy"] = np
545545

546546
print_(
@@ -556,7 +556,7 @@ def evaluate(
556556
verbose,
557557
)
558558

559-
if (type(v) == float or type(v) == str) and int(v) == v:
559+
if (type(v) is float or type(v) is str) and int(v) == v:
560560

561561
print_(" Returning int: %s" % int(v), verbose)
562562

@@ -583,7 +583,7 @@ def parse_list_like(list_str):
583583
return [list_str]
584584
elif isinstance(list_str, list):
585585
return list_str
586-
elif type(list_str) == str:
586+
elif type(list_str) is str:
587587
try:
588588
expr = int(list_str)
589589
return [expr]

tests/test_base.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -192,8 +192,9 @@ def test_save_load_json(tmp_path):
192192
nety3 = NewNetwork.from_yaml_file(filenamey)
193193
str_nety3 = str(nety3)
194194

195-
# datax = load_xml(filenamex)
196-
# print_v("Loaded network specification from %s" % filenamex)
195+
datax = load_xml(filenamex)
196+
assert len(datax) > 0
197+
print_v("Loaded network specification from %s" % filenamex)
197198

198199
# netx = NewNetwork.from_dict(datax)
199200
# str_netx = str(netx)

0 commit comments

Comments
 (0)