Предизвикателства > Безгрешен блок > Решения > Решението на Даниел Манчевски

Резултати
0 точки от тестове
0 точки от учител

0 точки общо

0 успешни теста
2 неуспешни теста
Код
Скрий всички коментари

 1class ProtectedSection:
 2    def __init__(self, **kwagrs):
 3        self.exception = None
 4        self.log = kwagrs["log"] if "log" in kwagrs else []
 5        self.suppress = kwagrs["suppress"] if "suppress" in kwagrs else []
 6
 7    def __enter__(self):
 8        return self
 9
10    def __exit__(self, exc_type, exc_val, exc_tb):
11        if issubclass(exc_type, Exception):
12            if exc_type in self.log:
13                self.exception = exc_val
14                return True
15            if exc_type in self.suppress:
16                return True
17        return False

EE
======================================================================
ERROR: test_solution (test.TestSolution.test_solution)
Test everything in a single test case. Only 100% gives a point.
----------------------------------------------------------------------
Traceback (most recent call last):
File "/tmp/test.py", line 24, in test_solution
with solution.ProtectedSection() as cm:
File "/tmp/solution.py", line 11, in __exit__
if issubclass(exc_type, Exception):
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: issubclass() arg 1 must be a class

======================================================================
ERROR: test_special_cases (test.TestSolution.test_special_cases)
Test special cases to show you that you missed something.
----------------------------------------------------------------------
Traceback (most recent call last):
File "/tmp/test.py", line 126, in test_special_cases
with protected_section as cm:
File "/tmp/solution.py", line 11, in __exit__
if issubclass(exc_type, Exception):
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: issubclass() arg 1 must be a class

----------------------------------------------------------------------
Ran 2 tests in 0.001s

FAILED (errors=2)

Дискусия
История
Това решение има само една версия.