Skip to content

Commit

Permalink
PEP-8 cleanups
Browse files Browse the repository at this point in the history
  • Loading branch information
timj committed Aug 4, 2016
1 parent 35fba01 commit 9649f60
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 8 deletions.
12 changes: 6 additions & 6 deletions python/lsst/__init__.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
#
#
# LSST Data Management System
# Copyright 2008, 2009, 2010 LSST Corporation.
#
#
# This product includes software developed by the
# LSST Project (http://www.lsst.org/).
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the LSST License Statement and
# the GNU General Public License along with this program. If not,
#
# You should have received a copy of the LSST License Statement and
# the GNU General Public License along with this program. If not,
# see <http://www.lsstcorp.org/LegalNotices/>.
#

Expand Down
19 changes: 18 additions & 1 deletion python/lsst/pex/exceptions/wrappers.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,15 @@

registry = {}


def register(cls):
"""A Python decorator that adds a Python exception wrapper to the registry that maps C++ Exceptions
to their Python wrapper classes.
"""
registry[cls.WrappedClass] = cls
return cls


class ExceptionMeta(type):
"""A metaclass for custom exception wrappers, which adds lookup of class attributes
by delegating to the Swig-generated wrapper.
Expand All @@ -23,6 +25,7 @@ class ExceptionMeta(type):
def __getattr__(self, name):
return getattr(self.WrappedClass, name)


@register
class Exception(with_metaclass(ExceptionMeta, builtins.Exception)):
"""The base class for Python-wrapped LSST C++ exceptions.
Expand Down Expand Up @@ -53,67 +56,81 @@ def __repr__(self):
def __str__(self):
return self.cpp.asString()


@register
class LogicError(Exception):
WrappedClass = exceptionsLib.LogicError


@register
class DomainError(LogicError):
WrappedClass = exceptionsLib.DomainError


@register
class InvalidParameterError(LogicError):
WrappedClass = exceptionsLib.InvalidParameterError


@register
class LengthError(LogicError):
WrappedClass = exceptionsLib.LengthError


@register
class OutOfRangeError(LogicError):
WrappedClass = exceptionsLib.OutOfRangeError


@register
class RuntimeError(Exception, builtins.RuntimeError):
WrappedClass = exceptionsLib.RuntimeError


@register
class RangeError(RuntimeError):
WrappedClass = exceptionsLib.RangeError


@register
class OverflowError(RuntimeError, builtins.OverflowError):
WrappedClass = exceptionsLib.OverflowError


@register
class UnderflowError(RuntimeError, builtins.ArithmeticError):
WrappedClass = exceptionsLib.UnderflowError


@register
class NotFoundError(Exception, builtins.LookupError):
WrappedClass = exceptionsLib.NotFoundError


@register
class MemoryError(RuntimeError, builtins.MemoryError):
WrappedClass = exceptionsLib.MemoryError


@register
class IoError(RuntimeError, builtins.IOError):
WrappedClass = exceptionsLib.IoError


@register
class TypeError(RuntimeError, builtins.TypeError):
WrappedClass = exceptionsLib.TypeError


@register
class TimeoutError(RuntimeError):
WrappedClass = exceptionsLib.TimeoutError


def translate(cpp):
"""Translate a C++ Exception instance to Python and return it."""
PyType = registry.get(type(cpp), None)
if PyType is None:
warnings.warn("Could not find appropriate Python type for C++ Exception")
PyType = Exception
return PyType(cpp)

2 changes: 1 addition & 1 deletion tests/Exception_2.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@

from builtins import str

import sys
import unittest

import lsst.pex.exceptions
import testLib


class ExceptionTestCase(unittest.TestCase):
"""A test case for C++/Python LsstCppExceptions."""

Expand Down

0 comments on commit 9649f60

Please sign in to comment.