Ticket #83 (new bug)

Opened 10 years ago

Last modified 9 years ago

Code cleanup: Class variable initialization

Reported by: Kaydeth_parpg Owned by: parpg
Priority: minor Milestone: Defect backlog
Component: scripts Version: trunk
Keywords: Cc:
Blocked By: Blocking:


2) Referencing instance variables in one method that were initialized in another without exception handling:

Code: ## Class Definition ## class MyClass2a:

def init(self):

print "Constructor for MyClass2a!"

def badMethod1a(self):

self.badVar = "bad!" #Instance variable initialized outside of constructor

def badMethod1b(self):

return self.badVar #Variable may not have been initialized before being used

## Object Instantiation ## myC2a = MyClass2a() myC2a.badMethod1b() # returns self.badVar which has never been initialized, will cause an AttributeError? exception

In this example, badMethod1a() initializes an instance variable self.badVar, and badMethod1b() returns that same variable. The problem arises is if badMethod1b() is called before badMethod1a(), then self.badVar will have never been initialized, and this too will cause an AttributeError? exception. I suggest at a minimum using some exception handling like the following:

See for more info.

The code should be scrubbed to remove these deficiencies.


Change History

comment:1 Changed 9 years ago by barra_parpg

  • Milestone changed from Techdemo 3 to Product backlog

moved techdemo 3 tickets to product backlog as we haven't agreed upon sprint goals for techdemo 3 yet

comment:2 Changed 9 years ago by barra_parpg

  • Milestone changed from Product backlog to Bugs

moved bugs to new bug milestone


Add a comment

Modify Ticket

as new

E-mail address and user name can be saved in the Preferences.

Note: See TracTickets for help on using tickets.