Skip to content
This repository was archived by the owner on Nov 2, 2022. It is now read-only.

native except handler API #21

Open
wants to merge 17 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions .appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ os: Visual Studio 2015

environment:
matrix:
- PYTHON: "C:\\Python35"
- PYTHON: "C:\\Python35-x64"
- PYTHON: "C:\\Python36"
- PYTHON: "C:\\Python36-x64"
- PYTHON: "C:\\Python37"
Expand Down
27 changes: 9 additions & 18 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
os: linux
language: python
sudo: false
dist: trusty
dist: focal

matrix:
include:
Expand All @@ -9,26 +9,17 @@ matrix:
env: CHECK_DOCS=1
- python: 3.6
env: CHECK_FORMATTING=1
# The pypy tests are slow, so list them early
- python: pypy3.5
# The pypy tests are slow, so we list them first
- python: pypy3.6-7.2.0
dist: bionic
# Uncomment if you want to test on pypy nightly:
# - language: generic
# env: USE_PYPY_NIGHTLY=1
- python: 3.5.0
- python: 3.5.2
# env: PYPY_NIGHTLY_BRANCH=py3.6
- python: 3.6
# As of 2018-07-05, Travis's 3.7 and 3.8 builds only work if you
# use dist: xenial AND sudo: required
# See: https://github.com/python-trio/trio/pull/556#issuecomment-402879391
- python: 3.7
dist: xenial
sudo: required
- python: 3.6-dev
- python: 3.7-dev
- python: 3.8-dev
dist: xenial
sudo: required
- os: osx
language: generic
env: MACPYTHON=3.5.4
- python: 3.9-dev
- os: osx
language: generic
env: MACPYTHON=3.6.6
Expand Down
60 changes: 1 addition & 59 deletions exceptiongroup/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,64 +4,6 @@

__all__ = ["ExceptionGroup", "split", "catch"]


class ExceptionGroup(BaseException):
"""An exception that contains other exceptions.

Its main use is to represent the situation when multiple child tasks all
raise errors "in parallel".

Args:
message (str): A description of the overall exception.
exceptions (list): The exceptions.
sources (list): For each exception, a string describing where it came
from.

Raises:
TypeError: if any of the passed in objects are not instances of
:exc:`BaseException`.
ValueError: if the exceptions and sources lists don't have the same
length.

"""

def __init__(self, message, exceptions, sources):
super().__init__(message, exceptions, sources)
self.exceptions = list(exceptions)
for exc in self.exceptions:
if not isinstance(exc, BaseException):
raise TypeError(
"Expected an exception object, not {!r}".format(exc)
)
self.message = message
self.sources = list(sources)
if len(self.sources) != len(self.exceptions):
raise ValueError(
"different number of sources ({}) and exceptions ({})".format(
len(self.sources), len(self.exceptions)
)
)

# copy.copy doesn't work for ExceptionGroup, because BaseException have
# rewrite __reduce_ex__ method. We need to add __copy__ method to
# make it can be copied.
def __copy__(self):
new_group = self.__class__(self.message, self.exceptions, self.sources)
new_group.__traceback__ = self.__traceback__
new_group.__context__ = self.__context__
new_group.__cause__ = self.__cause__
# Setting __cause__ also implicitly sets the __suppress_context__
# attribute to True. So we should copy __suppress_context__ attribute
# last, after copying __cause__.
new_group.__suppress_context__ = self.__suppress_context__
return new_group

def __str__(self):
return ", ".join(repr(exc) for exc in self.exceptions)

def __repr__(self):
return "<ExceptionGroup: {}>".format(self)


from ._exception_group import ExceptionGroup
from . import _monkeypatch
from ._tools import split, catch
Loading