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:
Saugat Pachhai
2021-01-19 18:33:18 +05:45
committed by GitHub
parent 372d6f045b
commit d8982c6db7
2 changed files with 7 additions and 3 deletions
+1
View File
@@ -7,6 +7,7 @@ class DvcException(Exception):
def __init__(self, msg, *args):
assert msg
self.msg = msg
super().__init__(msg, *args)
+6 -3
View File
@@ -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):