Add __str__ and __repr__ to Sanic and Bluepring (#2043)
This commit is contained in:
@@ -33,4 +33,8 @@ class BaseSanic(
|
||||
ExceptionMixin,
|
||||
metaclass=Base,
|
||||
):
|
||||
...
|
||||
def __str__(self) -> str:
|
||||
return f"<{self.__class__.__name__} {self.name}>"
|
||||
|
||||
def __repr__(self) -> str:
|
||||
return f'{self.__class__.__name__}(name="{self.name}")'
|
||||
|
||||
@@ -49,6 +49,23 @@ class Blueprint(BaseSanic):
|
||||
self.version = version
|
||||
self.strict_slashes = strict_slashes
|
||||
|
||||
def __repr__(self) -> str:
|
||||
args = ", ".join(
|
||||
[
|
||||
f'{attr}="{getattr(self, attr)}"'
|
||||
if isinstance(getattr(self, attr), str)
|
||||
else f"{attr}={getattr(self, attr)}"
|
||||
for attr in (
|
||||
"name",
|
||||
"url_prefix",
|
||||
"host",
|
||||
"version",
|
||||
"strict_slashes",
|
||||
)
|
||||
]
|
||||
)
|
||||
return f"Blueprint({args})"
|
||||
|
||||
def route(self, *args, **kwargs):
|
||||
kwargs["apply"] = False
|
||||
return super().route(*args, **kwargs)
|
||||
|
||||
Reference in New Issue
Block a user