Skip to content

Commit

Permalink
Disallow Uninitialized Variable Use (#521)
Browse files Browse the repository at this point in the history
Configure mypy to error when a potentially uninitialized variable is
used. Fix lingering errors found by mypy.

[ committed by @MattToast ]
[ reviewed by @al-rigazzi @ankona ]
  • Loading branch information
MattToast authored Mar 29, 2024
1 parent fa0da2c commit 6f800b1
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 15 deletions.
3 changes: 3 additions & 0 deletions doc/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ Detailed Notes
- Update the generic `t.Any` typehints in Experiment API. (SmartSim-PR501_)
- The CI will fail static analysis if common erroneous truthy checks are
detected. (SmartSim-PR524_)
- The CI will fail static analysis if a local variable used while potentially
undefined. (SmartSim-PR521_)
- Remove previously deprecated behavior present in test suite on machines with
Slurm and Open MPI. (SmartSim-PR520_)

Expand All @@ -77,6 +79,7 @@ Detailed Notes
.. _SmartSim-PR512: https://github.com/CrayLabs/SmartSim/pull/512
.. _SmartSim-PR529: https://github.com/CrayLabs/SmartSim/pull/529
.. _SmartSim-PR522: https://github.com/CrayLabs/SmartSim/pull/522
.. _SmartSim-PR521: https://github.com/CrayLabs/SmartSim/pull/521
.. _SmartSim-PR524: https://github.com/CrayLabs/SmartSim/pull/524
.. _SmartSim-PR520: https://github.com/CrayLabs/SmartSim/pull/520
.. _SmartSim-PR518: https://github.com/CrayLabs/SmartSim/pull/518
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ strict_equality = true
# Additional Error Codes
enable_error_code = [
# "redundant-expr",
# "possibly-undefined",
"possibly-undefined",
# "unused-awaitable",
# "ignore-without-code",
# "mutable-override",
Expand Down
8 changes: 5 additions & 3 deletions smartsim/_core/_cli/validate.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,8 @@ def execute(
simple experiment
"""
backends = installed_redisai_backends()
device: Device = Device(args.device)
temp_dir = ""
device = Device(args.device)
try:
with contextlib.ExitStack() as ctx:
temp_dir = ctx.enter_context(_VerificationTempDir(dir=os.getcwd()))
Expand All @@ -110,10 +111,11 @@ def execute(
except Exception as e:
logger.error(
"SmartSim failed to run a simple experiment!\n"
f"Experiment failed due to the following exception:\n{e}\n\n"
f"Output files are available at `{temp_dir}`",
f"Experiment failed due to the following exception:\n{e}",
exc_info=True,
)
if temp_dir:
logger.info(f"Output files are available at `{temp_dir}`")
return os.EX_SOFTWARE
return os.EX_OK

Expand Down
5 changes: 2 additions & 3 deletions smartsim/_core/entrypoints/colocated.py
Original file line number Diff line number Diff line change
Expand Up @@ -255,9 +255,8 @@ def launch_db_scripts(client: Client, db_scripts: t.List[t.List[str]]) -> None:
raise SSInternalError(
"Failed to set model or script, could not connect to database"
) from ex
finally:
# Make sure we don't keep this around
del client
# Make sure we don't keep this around
del client

except Exception as e:
cleanup()
Expand Down
15 changes: 7 additions & 8 deletions smartsim/ml/tf/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,21 +35,20 @@

try:
import tensorflow as tf

installed_tf = Version_(tf.__version__)
assert installed_tf >= "2.4.0"

except ImportError: # pragma: no cover
raise ModuleNotFoundError(
f"TensorFlow {TF_VERSION} is not installed. "
"Please install it to use smartsim.tf"
"Please install it to use smartsim.ml.tf"
) from None

try:
installed_tf = Version_(tf.__version__)
assert installed_tf >= TF_VERSION
except AssertionError: # pragma: no cover
msg = (
raise SmartSimError(
f"TensorFlow >= {TF_VERSION} is required for smartsim. "
f"tf, you have {tf.__version__}"
)
raise SmartSimError() from None
) from None


# pylint: disable=wrong-import-position
Expand Down

0 comments on commit 6f800b1

Please sign in to comment.