mirror of
https://github.com/Stone-Red-Code/dvc.git
synced 2026-11-02 07:18:25 +01:00
Override __str__ implementation for StageNotFound (#5289)
This happens because KeyError quotes the error message. We'd still like to keep StageNotFound being a KeyError semantics, but workaround the __str__ implementation. Mypy was having some problem with the previous `__str__` override.
This commit is contained in:
@@ -7,6 +7,7 @@ class DvcException(Exception):
|
||||
|
||||
def __init__(self, msg, *args):
|
||||
assert msg
|
||||
self.msg = msg
|
||||
super().__init__(msg, *args)
|
||||
|
||||
|
||||
|
||||
@@ -80,9 +80,7 @@ class MissingDataSource(DvcException):
|
||||
super().__init__(msg)
|
||||
|
||||
|
||||
class StageNotFound(KeyError, DvcException):
|
||||
__str__ = DvcException.__str__
|
||||
|
||||
class StageNotFound(DvcException, KeyError):
|
||||
def __init__(self, file, name):
|
||||
self.file = file.relpath
|
||||
self.name = name
|
||||
@@ -90,6 +88,11 @@ class StageNotFound(KeyError, DvcException):
|
||||
f"Stage '{self.name}' not found inside '{self.file}' file"
|
||||
)
|
||||
|
||||
def __str__(self):
|
||||
# `KeyError` quotes the message
|
||||
# see: https://bugs.python.org/issue2651
|
||||
return self.msg
|
||||
|
||||
|
||||
class StageNameUnspecified(DvcException):
|
||||
def __init__(self, file):
|
||||
|
||||
Reference in New Issue
Block a user