lots of PEP8 cleanup

This commit is contained in:
Ebag333
2016-10-19 12:25:31 -07:00
parent 74ce79ba8f
commit 0c0eb327f7
12 changed files with 65 additions and 41 deletions

View File

@@ -98,7 +98,7 @@ mapper(Fit, fits_table,
"_Fit__modules": relation(
Module,
collection_class=HandledModuleList,
primaryjoin=and_(modules_table.c.fitID == fits_table.c.ID, modules_table.c.projected == False),
primaryjoin=and_(modules_table.c.fitID == fits_table.c.ID, modules_table.c.projected is False),
order_by=modules_table.c.position,
cascade='all, delete, delete-orphan'),
"_Fit__projectedModules": relation(

View File

@@ -17,6 +17,7 @@
# along with eos. If not, see <http://www.gnu.org/licenses/>.
# ===============================================================================
class EqBase(object):
def __init__(self):
self.ID = None

View File

@@ -306,7 +306,7 @@ class ModifiedAttributeDict(collections.MutableMapping):
tbl = self.__postIncreases
else:
raise ValueError("position should be either pre or post")
if not attributeName in tbl:
if attributeName not in tbl:
tbl[attributeName] = 0
tbl[attributeName] += increase
self.__placehold(attributeName)
@@ -323,15 +323,15 @@ class ModifiedAttributeDict(collections.MutableMapping):
# If we're asked to do stacking penalized multiplication, append values
# to per penalty group lists
if stackingPenalties:
if not attributeName in self.__penalizedMultipliers:
if attributeName not in self.__penalizedMultipliers:
self.__penalizedMultipliers[attributeName] = {}
if not penaltyGroup in self.__penalizedMultipliers[attributeName]:
if penaltyGroup not in self.__penalizedMultipliers[attributeName]:
self.__penalizedMultipliers[attributeName][penaltyGroup] = []
tbl = self.__penalizedMultipliers[attributeName][penaltyGroup]
tbl.append(multiplier)
# Non-penalized multiplication factors go to the single list
else:
if not attributeName in self.__multipliers:
if attributeName not in self.__multipliers:
self.__multipliers[attributeName] = 1
self.__multipliers[attributeName] *= multiplier

View File

@@ -98,7 +98,7 @@ class Booster(HandledItem, ItemAttrShortcut):
return self.__item
def __calculateSlot(self, item):
if not "boosterness" in item.attributes:
if "boosterness" not in item.attributes:
raise ValueError("Passed item is not a booster")
return int(item.attributes["boosterness"].value)
@@ -107,8 +107,10 @@ class Booster(HandledItem, ItemAttrShortcut):
self.itemModifiedAttributes.clear()
def calculateModifiedAttributes(self, fit, runTime, forceProjected=False):
if forceProjected: return
if not self.active: return
if forceProjected:
return
if not self.active:
return
for effect in self.item.effects.itervalues():
if effect.runTime == runTime and effect.isType("passive"):
effect.handler(fit, self, ("booster",))

View File

@@ -216,7 +216,8 @@ class Character(object):
element.boostItemAttr(*args, **kwargs)
def calculateModifiedAttributes(self, fit, runTime, forceProjected=False):
if forceProjected: return
if forceProjected:
return
for skill in self.skills:
fit.register(skill)
skill.calculateModifiedAttributes(fit, runTime)
@@ -303,7 +304,7 @@ class Skill(HandledItem):
if (level < 0 or level > 5) and level is not None:
raise ValueError(str(level) + " is not a valid value for level")
if hasattr(self, "_Skill__ro") and self.__ro == True:
if hasattr(self, "_Skill__ro") and self.__ro is True:
raise ReadOnlyException()
self.activeLevel = level
@@ -337,8 +338,8 @@ class Skill(HandledItem):
return
for effect in item.effects.itervalues():
if effect.runTime == runTime and effect.isType("passive") and (
not fit.isStructure or effect.isType("structure")):
if effect.runTime == runTime and effect.isType("passive") and \
(not fit.isStructure or effect.isType("structure")):
try:
effect.handler(fit, self, ("skill",))
except AttributeError:
@@ -356,7 +357,7 @@ class Skill(HandledItem):
@validates("characterID", "skillID", "level")
def validator(self, key, val):
if hasattr(self, "_Skill__ro") and self.__ro == True and key != "characterID":
if hasattr(self, "_Skill__ro") and self.__ro is True and key != "characterID":
raise ReadOnlyException()
map = {"characterID": lambda val: isinstance(val, int),

View File

@@ -165,7 +165,8 @@ class Drone(HandledItem, HandledCharge, ItemAttrShortcut, ChargeAttrShortcut):
"ecmBurstRange", "maxRange")
for attr in attrs:
maxRange = self.getModifiedItemAttr(attr)
if maxRange is not None: return maxRange
if maxRange is not None:
return maxRange
if self.charge is not None:
delay = self.getModifiedChargeAttr("explosionDelay")
speed = self.getModifiedChargeAttr("maxVelocity")
@@ -180,7 +181,8 @@ class Drone(HandledItem, HandledCharge, ItemAttrShortcut, ChargeAttrShortcut):
attrs = ("falloff", "falloffEffectiveness")
for attr in attrs:
falloff = self.getModifiedItemAttr(attr)
if falloff is not None: return falloff
if falloff is not None:
return falloff
@validates("ID", "itemID", "chargeID", "amount", "amountActive")
def validator(self, key, val):
@@ -230,8 +232,8 @@ class Drone(HandledItem, HandledCharge, ItemAttrShortcut, ChargeAttrShortcut):
for effect in self.item.effects.itervalues():
if effect.runTime == runTime and \
((projected == True and effect.isType("projected")) or
projected == False and effect.isType("passive")):
((projected is True and effect.isType("projected")) or
projected is False and effect.isType("passive")):
# See GH issue #765
if effect.getattr('grouped'):
effect.handler(fit, self, context)

View File

@@ -167,7 +167,9 @@ class Fighter(HandledItem, HandledCharge, ItemAttrShortcut, ChargeAttrShortcut):
self.__dps += dps
self.__volley += volley
# For forward compatability this assumes a fighter can have more than 2 damaging abilities and/or multiple that use charges.
# For forward compatability this assumes a fighter
# can have more than 2 damaging abilities and/or
# multiple that use charges.
if self.owner.factorReload:
activeTimes = []
reloadTimes = []
@@ -196,7 +198,8 @@ class Fighter(HandledItem, HandledCharge, ItemAttrShortcut, ChargeAttrShortcut):
"ecmBurstRange", "maxRange")
for attr in attrs:
maxRange = self.getModifiedItemAttr(attr)
if maxRange is not None: return maxRange
if maxRange is not None:
return maxRange
if self.charge is not None:
delay = self.getModifiedChargeAttr("explosionDelay")
speed = self.getModifiedChargeAttr("maxVelocity")
@@ -211,7 +214,8 @@ class Fighter(HandledItem, HandledCharge, ItemAttrShortcut, ChargeAttrShortcut):
attrs = ("falloff", "falloffEffectiveness")
for attr in attrs:
falloff = self.getModifiedItemAttr(attr)
if falloff is not None: return falloff
if falloff is not None:
return falloff
@validates("ID", "itemID", "chargeID", "amount", "amountActive")
def validator(self, key, val):

View File

@@ -96,9 +96,9 @@ class FighterAbility(object):
@property
def reloadTime(self):
return self.fighter.getModifiedItemAttr("fighterRefuelingTime") + (self.REARM_TIME_MAPPING[
self.fighter.getModifiedItemAttr(
"fighterSquadronRole")] or 0 if self.hasCharges else 0) * self.numShots
return self.fighter.getModifiedItemAttr("fighterRefuelingTime") + \
(self.REARM_TIME_MAPPING[self.fighter.getModifiedItemAttr(
"fighterSquadronRole")] or 0 if self.hasCharges else 0) * self.numShots
@property
def numShots(self):

View File

@@ -18,7 +18,6 @@
# ===============================================================================
import copy
import logging
import time
from copy import deepcopy
from itertools import chain
@@ -877,7 +876,8 @@ class Fit(object):
# calculate how much the repper can rep stability & add to total
totalPeakRecharge = self.capRecharge
for mod in repairers:
if capUsed > totalPeakRecharge: break
if capUsed > totalPeakRecharge:
break
cycleTime = mod.cycleTime
capPerSec = mod.capUse
if capPerSec is not None and cycleTime is not None:
@@ -886,8 +886,7 @@ class Fit(object):
# Add the sustainable amount
amount = mod.getModifiedItemAttr(groupAttrMap[mod.item.group.name])
sustainable[groupStoreMap[mod.item.group.name]] += sustainability * (
amount / (cycleTime / 1000.0))
sustainable[groupStoreMap[mod.item.group.name]] += sustainability * (amount / (cycleTime / 1000.0))
capUsed += capPerSec
sustainable["passiveShield"] = self.calculateShieldRecharge()
@@ -1096,8 +1095,15 @@ class Fit(object):
copy.targetResists = self.targetResists
toCopy = (
"modules", "drones", "fighters", "cargo", "implants", "boosters", "projectedModules", "projectedDrones",
"projectedFighters")
"modules",
"drones",
"fighters",
"cargo",
"implants",
"boosters",
"projectedModules",
"projectedDrones",
"projectedFighters")
for name in toCopy:
orig = getattr(self, name)
c = getattr(copy, name)

View File

@@ -27,7 +27,8 @@ class Fleet(object):
def calculateModifiedAttributes(self):
# Make sure ALL fits in the gang have been calculated
for c in chain(self.wings, (self.leader,)):
if c is not None: c.calculateModifiedAttributes()
if c is not None:
c.calculateModifiedAttributes()
leader = self.leader
self.booster = booster = self.booster if self.booster is not None else leader
@@ -91,7 +92,8 @@ class Fleet(object):
class Wing(object):
def calculateModifiedAttributes(self):
for c in chain(self.squads, (self.leader,)):
if c is not None: c.calculateModifiedAttributes()
if c is not None:
c.calculateModifiedAttributes()
def calculateGangBonusses(self, store):
self.broken = False

View File

@@ -79,7 +79,7 @@ class Implant(HandledItem, ItemAttrShortcut):
return self.__item
def __calculateSlot(self, item):
if not "implantness" in item.attributes:
if "implantness" not in item.attributes:
raise ValueError("Passed item is not an implant")
return int(item.attributes["implantness"].value)
@@ -88,8 +88,10 @@ class Implant(HandledItem, ItemAttrShortcut):
self.itemModifiedAttributes.clear()
def calculateModifiedAttributes(self, fit, runTime, forceProjected=False):
if forceProjected: return
if not self.active: return
if forceProjected:
return
if not self.active:
return
for effect in self.item.effects.itervalues():
if effect.runTime == runTime and effect.isType("passive"):
effect.handler(fit, self, ("implant",))

View File

@@ -169,8 +169,7 @@ class Module(HandledItem, HandledCharge, ItemAttrShortcut, ChargeAttrShortcut):
def isInvalid(self):
if self.isEmpty:
return False
return self.__item is None or (self.__item.category.name not in (
"Module", "Subsystem", "Structure Module") and self.__item.group.name != "Effect Beacon")
return self.__item is None or (self.__item.category.name not in ("Module", "Subsystem", "Structure Module") and self.__item.group.name != "Effect Beacon")
@property
def numCharges(self):
@@ -252,7 +251,8 @@ class Module(HandledItem, HandledCharge, ItemAttrShortcut, ChargeAttrShortcut):
"shipScanRange", "surveyScanRange")
for attr in attrs:
maxRange = self.getModifiedItemAttr(attr)
if maxRange is not None: return maxRange
if maxRange is not None:
return maxRange
if self.charge is not None:
try:
chargeName = self.charge.group.name
@@ -280,7 +280,8 @@ class Module(HandledItem, HandledCharge, ItemAttrShortcut, ChargeAttrShortcut):
attrs = ("falloffEffectiveness", "falloff", "shipScanFalloff")
for attr in attrs:
falloff = self.getModifiedItemAttr(attr)
if falloff is not None: return falloff
if falloff is not None:
return falloff
@property
def slot(self):
@@ -513,7 +514,8 @@ class Module(HandledItem, HandledCharge, ItemAttrShortcut, ChargeAttrShortcut):
def isValidCharge(self, charge):
# Check sizes, if 'charge size > module volume' it won't fit
if charge is None: return True
if charge is None:
return True
chargeVolume = charge.volume
moduleCapacity = self.item.capacity
if chargeVolume is not None and moduleCapacity is not None and chargeVolume > moduleCapacity:
@@ -528,8 +530,10 @@ class Module(HandledItem, HandledCharge, ItemAttrShortcut, ChargeAttrShortcut):
chargeGroup = charge.groupID
for i in range(5):
itemChargeGroup = self.getModifiedItemAttr('chargeGroup' + str(i))
if itemChargeGroup is None: continue
if itemChargeGroup == chargeGroup: return True
if itemChargeGroup is None:
continue
if itemChargeGroup == chargeGroup:
return True
return False