Skip to content

Three undefined names found by static analysis (one reachable NameError) #16

Description

@musicalplatypus

Running pyflakes across the repository surfaces three undefined names on main (378dd15). They are unrelated to each other and differ in severity, so I have listed them separately. Happy to send a PR for any or all of them if that is useful.

Reproduce with:

pip install pyflakes
pyflakes $(git ls-files '*.py')

1. T is undefined in the audio keyword-spotting example — reachable

tinyml-modeloptimization/torchmodelopt/examples/audio_keyword_spotting/main.py:243

def compute_torchMFCC(self, audio_tensor):
    __MFCC = T.MFCC( # type: ignore

T is never imported in the file. The method is called at line 203, so this raises NameError: name 'T' is not defined whenever that path executes. The # type: ignore suggests a type checker flagged it previously.

Looks like a missing import torchaudio.transforms as T, but I did not want to guess the intended module.


2. __all__ lists a name that does not exist

tinyml-modelzoo/tinyml_modelzoo/models/classification.py:985

    'TEST_NEW_MODEL_2K',

TEST_NEW_MODEL_2K is not defined anywhere in the file. Python raises AttributeError for a from ... import * when __all__ names a missing symbol, so this breaks star-imports of the module. The name suggests leftover scaffolding.


3. value is undefined in image_base.py — latent, currently unreachable

tinyml-modelmaker/tinyml_modelmaker/ai_modules/vision/training/tinyml_tinyverse/image_base.py:242-245

    @classmethod
    def init_params(cls, *args, **kwargs):
        params = dict(training=dict())
        params = utils.ConfigDict(params, *args, **kwargs)
        return params

    # @staticmethod
    # def _argv_value(value):
    #     if value is None:
    #         return "None"

        if isinstance(value, (list, tuple)):
            return repr(list(value))

        return str(value)

A _argv_value static method was partially commented out: the decorator, def line and first branch are commented, but the rest of the body is not. Python therefore parses the remaining lines as trailing statements of init_params, after its return, so they are unreachable and cannot raise at runtime today.

Not currently a bug, but the dead fragment is misleading, and it would start executing if init_params were ever edited above it. _argv_value has no callers, so deleting the fragment outright looks correct.


For completeness: a separate missing import numpy as np in three references/*/test_onnx.py scripts produces the same class of error on the nn_for_feature_extraction path. That one is already included in PR #8.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions