Skip to content

Implement __repr__ for route classes#1864

Merged
Kludex merged 17 commits intoKludex:masterfrom
alex-oleshkevich:route-repr
Sep 23, 2022
Merged

Implement __repr__ for route classes#1864
Kludex merged 17 commits intoKludex:masterfrom
alex-oleshkevich:route-repr

Conversation

@alex-oleshkevich
Copy link
Contributor

@alex-oleshkevich alex-oleshkevich commented Sep 22, 2022

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

image

@Kludex
Copy link
Owner

Kludex commented Sep 22, 2022

Are you strong about the style in this PR or can we do:

Route(path="/login", name="login", methods={"GET", "POST"})

?

@alex-oleshkevich alex-oleshkevich changed the title Implement __repr__ for Route Implement __repr__ for route classes Sep 22, 2022
@alex-oleshkevich alex-oleshkevich marked this pull request as ready for review September 22, 2022 11:59
@alex-oleshkevich
Copy link
Contributor Author

Are you strong about the style in this PR or can we do:

Route(path="/login", name="login", methods={"GET", "POST"})

?

No, that's a matter of taste. If you think the proposed solution is more readable, I am fine to change.

@Kludex Kludex added this to the Version 0.21.0 milestone Sep 22, 2022
Copy link
Owner

@Kludex Kludex left a 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 ?

def __repr__(self) -> str:
return (
f"<{self.__class__.__name__}: "
f"path={self.path}, name={self.name or ''}, app={self.app}>"
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Suggested change
f"path={self.path}, name={self.name or ''}, app={self.app}>"
f"path={self.path}, name={self.name or ''}, app={self.app!r}>"

Copy link
Owner

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 🤔

Copy link
Owner

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!

@Kludex Kludex mentioned this pull request Sep 22, 2022
8 tasks
Copy link
Owner

@Kludex Kludex left a 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. 👀

alex-oleshkevich and others added 10 commits September 22, 2022 19:32
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>
Copy link
Owner

@Kludex Kludex left a 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 🙏

@alex-oleshkevich
Copy link
Contributor Author

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. +1

Thanks for making an effort to improve our users' lives @alex-oleshkevich pray

okay, i will remove it. this is too confusing.

Kludex
Kludex previously approved these changes Sep 22, 2022
@Kludex
Copy link
Owner

Kludex commented Sep 22, 2022

image

I'm not able to merge it 😅

@Kludex
Copy link
Owner

Kludex commented Sep 22, 2022

Does anyone know why I can't merge? 🤔

@alex-oleshkevich
Copy link
Contributor Author

@Kludex what's behind "statuses" link?

@Kludex
Copy link
Owner

Kludex commented Sep 23, 2022

@Kludex what's behind "statuses" link?

https://docs.github.com/rest/commits/statuses

@Kludex Kludex dismissed their stale review September 23, 2022 12:41

I'm not able to merge.

@Kludex Kludex marked this pull request as draft September 23, 2022 12:43
@Kludex Kludex marked this pull request as ready for review September 23, 2022 12:43
@Kludex
Copy link
Owner

Kludex commented Sep 23, 2022

I don't know 👍

@Kludex
Copy link
Owner

Kludex commented Sep 23, 2022

The target is wrong... It should be "master", but it's "encode:master"... I don't know what happened here.

image

@Kludex Kludex changed the base branch from master to security-policy September 23, 2022 12:52
@Kludex Kludex changed the base branch from security-policy to master September 23, 2022 12:52
@Kludex Kludex merged commit 70971ea into Kludex:master Sep 23, 2022
@Kludex
Copy link
Owner

Kludex commented Sep 23, 2022

Easy. 👀

aminalaee pushed a commit that referenced this pull request Feb 13, 2023
* 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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants