-
-
Notifications
You must be signed in to change notification settings - Fork 932
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, the !r
is used on all parameters in the other __repr__
that we have in code 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, I got why... It's because with them, there's no need to wrap on parenthesis!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The comments are mainly to comply with the style we have on the other __repr__
. 🙏
I think the suggestions on the tests are correct, but not sure. 👀
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>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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: