Skip to content
This repository has been archived by the owner on Aug 27, 2023. It is now read-only.

Commit

Permalink
PEP8 cleanups
Browse files Browse the repository at this point in the history
  • Loading branch information
stevearc committed Feb 23, 2015
1 parent 6f29b70 commit e9af01b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 13 deletions.
4 changes: 2 additions & 2 deletions flywheel/__init__.py
@@ -1,6 +1,4 @@
""" flywheel """
__version__ = '0.4.0'

from dynamo3 import (CheckFailed, ConditionalCheckFailedException, Binary,
STRING, NUMBER, BINARY, STRING_SET, NUMBER_SET,
BINARY_SET)
Expand All @@ -9,3 +7,5 @@
from .models import Model
from .engine import Engine
from .query import DuplicateEntityException, EntityNotFoundException

__version__ = '0.4.0'
23 changes: 12 additions & 11 deletions flywheel/models.py
Expand Up @@ -179,12 +179,15 @@ def __new__(cls, *_, **__):
obj._persisted = False
return obj

def _is_field_primary(self, key):
""" Check if a given field is part of the primary key """
return ((self.meta_.hash_key.name in self.meta_.related_fields[key]) or
(self.meta_.range_key is not None and
self.meta_.range_key.name in self.meta_.related_fields[key]))

def __setattr__(self, name, value):
if self.persisted_:
if ((self.meta_.hash_key.name in self.meta_.related_fields[name])
or (self.meta_.range_key is not None and
self.meta_.range_key.name in
self.meta_.related_fields[name])):
if self._is_field_primary(name):
if value != getattr(self, name):
raise AttributeError(
"Cannot change an item's primary key!")
Expand Down Expand Up @@ -299,10 +302,7 @@ def cached_(self, name, default=None):
def incr_(self, **kwargs):
""" Atomically increment a number value """
for key, val in six.iteritems(kwargs):
if ((self.meta_.hash_key.name in self.meta_.related_fields[key])
or (self.meta_.range_key is not None and
self.meta_.range_key.name in
self.meta_.related_fields[key])):
if self._is_field_primary(key):
raise AttributeError("Cannot increment an item's primary key!")

field = self.meta_.fields.get(key)
Expand Down Expand Up @@ -484,9 +484,10 @@ def __hash__(self):
return hash(self.hk_) + hash(self.rk_)

def __eq__(self, other):
return (isinstance(other, self.__class__)
and self.meta_.name == other.meta_.name and self.hk_ == other.hk_
and self.rk_ == other.rk_)
return (isinstance(other, self.__class__) and
self.meta_.name == other.meta_.name and
self.hk_ == other.hk_ and
self.rk_ == other.rk_)

def __ne__(self, other):
return not self.__eq__(other)

0 comments on commit e9af01b

Please sign in to comment.