From a04748e868f21b8c9a3e9bd8d8582ad22b1e2040 Mon Sep 17 00:00:00 2001 From: Julien Danjou Date: Wed, 18 Sep 2013 11:18:28 +0200 Subject: [PATCH] Minor code cleanups Change-Id: I338656e8f131b36aae342af94f1c2cedad14ae2b --- wsme/api.py | 4 ++-- wsme/rest/__init__.py | 12 ++++++------ wsme/types.py | 7 ++----- wsmeext/sphinxext.py | 14 +++++++------- wsmeext/sqlalchemy/types.py | 2 +- 5 files changed, 18 insertions(+), 21 deletions(-) diff --git a/wsme/api.py b/wsme/api.py index 7de462c..6bd181d 100644 --- a/wsme/api.py +++ b/wsme/api.py @@ -83,8 +83,8 @@ class FunctionDefinition(object): #: Dictionnary of protocol-specific options. self.extra_options = None - @classmethod - def get(cls, func): + @staticmethod + def get(func): """ Returns the :class:`FunctionDefinition` of a method. """ diff --git a/wsme/rest/__init__.py b/wsme/rest/__init__.py index 3153a49..f35d6a9 100644 --- a/wsme/rest/__init__.py +++ b/wsme/rest/__init__.py @@ -12,25 +12,25 @@ class expose(object): return self.signature(func) @classmethod - def with_method(self, method, *args, **kwargs): + def with_method(cls, method, *args, **kwargs): kwargs['method'] = method - return expose(*args, **kwargs) + return cls(*args, **kwargs) @classmethod def get(cls, *args, **kwargs): - return expose.with_method('GET', *args, **kwargs) + return cls.with_method('GET', *args, **kwargs) @classmethod def post(cls, *args, **kwargs): - return expose.with_method('POST', *args, **kwargs) + return cls.with_method('POST', *args, **kwargs) @classmethod def put(cls, *args, **kwargs): - return expose.with_method('PUT', *args, **kwargs) + return cls.with_method('PUT', *args, **kwargs) @classmethod def delete(cls, *args, **kwargs): - return expose.with_method('DELETE', *args, **kwargs) + return cls.with_method('DELETE', *args, **kwargs) class validate(object): diff --git a/wsme/types.py b/wsme/types.py index 1856a83..46716b8 100644 --- a/wsme/types.py +++ b/wsme/types.py @@ -438,15 +438,12 @@ def inspect_class(class_): if inspect.isroutine(attr): continue - if isinstance(attr, wsattr): - attrdef = attr - elif isinstance(attr, wsproperty): + if isinstance(attr, (wsattr, wsproperty)): attrdef = attr else: if attr not in native_types and ( inspect.isclass(attr) - or isinstance(attr, list) - or isinstance(attr, dict)): + or isinstance(attr, (list, dict))): register_type(attr) attrdef = getattr(class_, '__wsattrclass__', wsattr)(attr) diff --git a/wsmeext/sphinxext.py b/wsmeext/sphinxext.py index 0f63f7b..f905e9a 100644 --- a/wsmeext/sphinxext.py +++ b/wsmeext/sphinxext.py @@ -76,7 +76,7 @@ class SampleType(object): @classmethod def sample(cls): - return SampleType(10) + return cls(10) class SampleService(wsme.WSRoot): @@ -194,8 +194,8 @@ class TypeDocumenter(autodoc.ClassDocumenter): 'samples-slot': check_samples_slot, }) - @classmethod - def can_document_member(cls, member, membername, isattr, parent): + @staticmethod + def can_document_member(member, membername, isattr, parent): # we don't want to be automaticaly used # TODO check if the member is registered an an exposed type return False @@ -271,8 +271,8 @@ class AttributeDocumenter(autodoc.AttributeDocumenter): datatype = None domain = 'wsme' - @classmethod - def can_document_member(cls, member, membername, isattr, parent): + @staticmethod + def can_document_member(member, membername, isattr, parent): return isinstance(parent, TypeDocumenter) def import_object(self): @@ -483,8 +483,8 @@ class FunctionDocumenter(autodoc.MethodDocumenter): 'method': directives.unchanged } - @classmethod - def can_document_member(cls, member, membername, isattr, parent): + @staticmethod + def can_document_member(member, membername, isattr, parent): return (isinstance(parent, ServiceDocumenter) and wsme.api.iswsmefunction(member)) diff --git a/wsmeext/sqlalchemy/types.py b/wsmeext/sqlalchemy/types.py index 13c67ec..da5603d 100644 --- a/wsmeext/sqlalchemy/types.py +++ b/wsmeext/sqlalchemy/types.py @@ -18,7 +18,7 @@ class SQLAlchemyRegistry(object): @classmethod def get(cls, registry): if not hasattr(registry, 'sqlalchemy'): - registry.sqlalchemy = SQLAlchemyRegistry() + registry.sqlalchemy = cls() return registry.sqlalchemy def __init__(self):