Skip to content

Commit 7caf930

Browse files
[REGRESSION] Various fixes and debugging from review (- WIP PR #169 -)
Changes in file multicast/__init__.py: - dropped redundent global syntax Changes in file multicast/exceptions.py: - fixed class CommandExecutionError's __init__ by reverting.
1 parent 77f7019 commit 7caf930

File tree

2 files changed

+13
-6
lines changed

2 files changed

+13
-6
lines changed

multicast/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -358,8 +358,8 @@
358358
raise ModuleNotFoundError("FAIL: we could not import Abstract base class. ABORT.") from None
359359

360360

361-
global EXIT_CODES # skipcq: PYL-W0604
362-
global EXCEPTION_EXIT_CODES # skipcq: PYL-W0604
361+
# global EXIT_CODES # skipcq: PYL-W0604
362+
# global EXCEPTION_EXIT_CODES # skipcq: PYL-W0604
363363
if 'multicast.exceptions' not in sys.modules:
364364
# pylint: disable=cyclic-import - skipcq: PYL-R0401, PYL-C0414
365365
from . import exceptions # pylint: disable=cyclic-import - skipcq: PYL-R0401, PYL-C0414

multicast/exceptions.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ class CommandExecutionError(RuntimeError):
167167
B. - checks inheritance.
168168
C. - checks each attribute.
169169
170-
>>> error = CommandExecutionError("Failed to execute command", exit_code=1)
170+
>>> error = CommandExecutionError("Failed to execute command", 1)
171171
>>> isinstance(error, RuntimeError)
172172
True
173173
>>> error.message
@@ -186,6 +186,9 @@ def __init__(self, *args, **kwargs):
186186
*args: Variable length argument list.
187187
**kwargs: Arbitrary keyword arguments.
188188
189+
Raises:
190+
TypeError: if the exit_code is not an int.
191+
189192
Meta-Testing:
190193
191194
Testcase 1: Initialization with different exit code:
@@ -199,9 +202,13 @@ def __init__(self, *args, **kwargs):
199202
>>> error.exit_code
200203
2
201204
"""
202-
exit_code = kwargs.pop("exit_code", 1)
203-
message = args[0] if args else kwargs.get("message", "An error occurred")
204-
super().__init__(message)
205+
if len(args) > 0 and isinstance(args[-1], int):
206+
exit_code = args[-1]
207+
args = args[:-1]
208+
else:
209+
exit_code = kwargs.pop("exit_code", 1)
210+
super().__init__(*args, **kwargs)
211+
self.message = args[0] if args else kwargs.get("message", "An error occurred")
205212
self.exit_code = exit_code
206213

207214

0 commit comments

Comments
 (0)