Menu

#1361 code analysis misses use of name in class namespace

open
Editor (491)
5
2011-07-26
2011-07-26
J D
No

Code analysis produces an "unused import" diagnostic for TensionState in this code:
[quote]
class TensionStatus(object):
from States import TensionState
def __init__(self):
self.state = self.TensionState.Off
[/quote]

However, this code does not produce the warning:
[quote]
from States import TensionState
class TensionStatus(object):
def __init__(self):
self.state = TensionState.Off
[/quote]

Both run correctly, but the second one adds an unneeded entry in the module's global name table.

In the case of the first example, changing the assignment to:
[quote] self.state = self.__class__.TensionState.Off[/quote]
does not remove the diagnostic. Similarly,
[quote] self.state = self.TensionStatus.TensionState.Off[/quote]
also does not remove the diagnostic.

Discussion

  • J D

    J D - 2011-07-26

    I apologize, I was not aware of how to use the formatting commands and there is no preview function.
    The first example should be:
    {{{
    class TensionStatus(object):
    from States import TensionState
    def __init__(self):
    self.state = self.TensionState.Off
    }}}
    and the second should be:
    {{{
    from States import TensionState
    class TensionStatus(object):
    def __init__(self):
    self.state = TensionState.Off
    }}}

     
  • J D

    J D - 2011-07-26

    How embarrassing.

     
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.