Implement __repr__ for route classes#1864
Conversation
|
Are you strong about the style in this PR or can we do: ? |
No, that's a matter of taste. If you think the proposed solution is more readable, I am fine to change. |
There was a problem hiding this comment.
My previous comment is not an opinion anymore, as I've noticed that we are already using the style I mentioned in our source code. Would you mind adapting it @alex-oleshkevich ?
starlette/routing.py
Outdated
| def __repr__(self) -> str: | ||
| return ( | ||
| f"<{self.__class__.__name__}: " | ||
| f"path={self.path}, name={self.name or ''}, app={self.app}>" |
There was a problem hiding this comment.
👍
| f"path={self.path}, name={self.name or ''}, app={self.app}>" | |
| f"path={self.path}, name={self.name or ''}, app={self.app!r}>" |
There was a problem hiding this comment.
Actually, the !r is used on all parameters in the other __repr__ that we have in code 🤔
There was a problem hiding this comment.
Ah, I got why... It's because with them, there's no need to wrap on parenthesis!
Co-authored-by: Marcelo Trylesinski <marcelotryle@gmail.com>
Co-authored-by: Marcelo Trylesinski <marcelotryle@gmail.com>
Co-authored-by: Marcelo Trylesinski <marcelotryle@gmail.com>
Co-authored-by: Marcelo Trylesinski <marcelotryle@gmail.com>
Co-authored-by: Marcelo Trylesinski <marcelotryle@gmail.com>
Co-authored-by: Marcelo Trylesinski <marcelotryle@gmail.com>
Co-authored-by: Marcelo Trylesinski <marcelotryle@gmail.com>
Co-authored-by: Marcelo Trylesinski <marcelotryle@gmail.com>
Co-authored-by: Marcelo Trylesinski <marcelotryle@gmail.com>
Kludex
left a comment
There was a problem hiding this comment.
I'm not sure about the Router.__repr__, as I don't see much value there, but I'll let you judge that.
Let me know your judgement, and I'll merge it. 👍
Thanks for making an effort to improve our users' lives @alex-oleshkevich 🙏
okay, i will remove it. this is too confusing. |
|
Does anyone know why I can't merge? 🤔 |
|
@Kludex what's behind "statuses" link? |
|
|
I don't know 👍 |
|
Easy. 👀 |
* implement __repr__ for Route * implemenr __repr__ for WebSocketRoute, Host, and Mount. * fix linting issues * change repr format * force repr() for inner apps * Update starlette/routing.py Co-authored-by: Marcelo Trylesinski <marcelotryle@gmail.com> * Update starlette/routing.py Co-authored-by: Marcelo Trylesinski <marcelotryle@gmail.com> * Update starlette/routing.py Co-authored-by: Marcelo Trylesinski <marcelotryle@gmail.com> * Update starlette/routing.py Co-authored-by: Marcelo Trylesinski <marcelotryle@gmail.com> * Update tests/test_routing.py Co-authored-by: Marcelo Trylesinski <marcelotryle@gmail.com> * Update tests/test_routing.py Co-authored-by: Marcelo Trylesinski <marcelotryle@gmail.com> * Update tests/test_routing.py Co-authored-by: Marcelo Trylesinski <marcelotryle@gmail.com> * Update tests/test_routing.py Co-authored-by: Marcelo Trylesinski <marcelotryle@gmail.com> * Update tests/test_routing.py Co-authored-by: Marcelo Trylesinski <marcelotryle@gmail.com> * fix linting issues and tests * remove repr from Router Co-authored-by: Marcelo Trylesinski <marcelotryle@gmail.com>


This little quality of life improvement makes debugging a bit easier by providing route information in the debugger: