From 0c0eb327f769f319e73028efa999f573da62c49a Mon Sep 17 00:00:00 2001 From: Ebag333 Date: Wed, 19 Oct 2016 12:25:31 -0700 Subject: [PATCH] lots of PEP8 cleanup --- eos/db/saveddata/fit.py | 2 +- eos/eqBase.py | 1 + eos/modifiedAttributeDict.py | 8 ++++---- eos/saveddata/booster.py | 8 +++++--- eos/saveddata/character.py | 11 ++++++----- eos/saveddata/drone.py | 10 ++++++---- eos/saveddata/fighter.py | 10 +++++++--- eos/saveddata/fighterAbility.py | 6 +++--- eos/saveddata/fit.py | 18 ++++++++++++------ eos/saveddata/fleet.py | 6 ++++-- eos/saveddata/implant.py | 8 +++++--- eos/saveddata/module.py | 18 +++++++++++------- 12 files changed, 65 insertions(+), 41 deletions(-) diff --git a/eos/db/saveddata/fit.py b/eos/db/saveddata/fit.py index bf7e336e1..977b34e5e 100644 --- a/eos/db/saveddata/fit.py +++ b/eos/db/saveddata/fit.py @@ -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( diff --git a/eos/eqBase.py b/eos/eqBase.py index 8c71e1a08..e85c5a8c0 100644 --- a/eos/eqBase.py +++ b/eos/eqBase.py @@ -17,6 +17,7 @@ # along with eos. If not, see . # =============================================================================== + class EqBase(object): def __init__(self): self.ID = None diff --git a/eos/modifiedAttributeDict.py b/eos/modifiedAttributeDict.py index 5f5e898a7..e0e846c3c 100644 --- a/eos/modifiedAttributeDict.py +++ b/eos/modifiedAttributeDict.py @@ -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 diff --git a/eos/saveddata/booster.py b/eos/saveddata/booster.py index 84369633d..0a46d662c 100644 --- a/eos/saveddata/booster.py +++ b/eos/saveddata/booster.py @@ -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",)) diff --git a/eos/saveddata/character.py b/eos/saveddata/character.py index 49229eee2..767441a6a 100644 --- a/eos/saveddata/character.py +++ b/eos/saveddata/character.py @@ -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), diff --git a/eos/saveddata/drone.py b/eos/saveddata/drone.py index 03e52fe7c..f847c1764 100644 --- a/eos/saveddata/drone.py +++ b/eos/saveddata/drone.py @@ -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) diff --git a/eos/saveddata/fighter.py b/eos/saveddata/fighter.py index fe0b6146a..635fa6db8 100644 --- a/eos/saveddata/fighter.py +++ b/eos/saveddata/fighter.py @@ -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): diff --git a/eos/saveddata/fighterAbility.py b/eos/saveddata/fighterAbility.py index b2af74e05..2f49336f6 100644 --- a/eos/saveddata/fighterAbility.py +++ b/eos/saveddata/fighterAbility.py @@ -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): diff --git a/eos/saveddata/fit.py b/eos/saveddata/fit.py index 36c2f8d13..baef29d1a 100644 --- a/eos/saveddata/fit.py +++ b/eos/saveddata/fit.py @@ -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) diff --git a/eos/saveddata/fleet.py b/eos/saveddata/fleet.py index fccb95ed8..6fc1b6330 100644 --- a/eos/saveddata/fleet.py +++ b/eos/saveddata/fleet.py @@ -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 diff --git a/eos/saveddata/implant.py b/eos/saveddata/implant.py index 7a4bf1790..4682403aa 100644 --- a/eos/saveddata/implant.py +++ b/eos/saveddata/implant.py @@ -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",)) diff --git a/eos/saveddata/module.py b/eos/saveddata/module.py index 45f8773b7..2c9a65254 100644 --- a/eos/saveddata/module.py +++ b/eos/saveddata/module.py @@ -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