Add Located::start, Located::end and impl Deref#4929
Add Located::start, Located::end and impl Deref#4929youknowone merged 1 commit intoRustPython:mainfrom
Located::start, Located::end and impl Deref#4929Conversation
Thank you for chiming in on the PR, suggesting to upstream these changes and merging them so quickly. It's great fun contributing to RustPython thanks to you :) |
|
I'd slightly push back on Deref here, docs boldly state it should only be implemented on smart pointer types but we might already be doing it in other places so 😄 |
We can undo the change if you feel strongly about. The term smart-pointer isn't well defined and there's ongoing discussion to re-phrase or even remove the section rust-lang/rust#91004. The way I think about it is that |
|
I definitely do not feel that strongly! |
|
Maybe it can be anti-pattern, but we already depends on a lot for Deref for thin wrappers. And it is abused a lot in many projects 😂 . Replacing them to traits will be possible but will be painful. I hope rust have a similar features allows method call for wrappers but disallow @MichaReiser Thank you so much for paying attention to keep unified code base. You are most welcome! |
|
FYI: Some better guidance on when and when not to |
This is a follow-up to #4192 and is motivated by the discussions in astral-sh#4
The PR adds the
startandendmethods toLocatedthat return a node's start or end location. Theendmethod falls back to returninglocationifend_locationisNone.The PR further implements
DerefforLocatedso that the node's fields and methods can be accessed directly: You can writelocated.fieldinstead oflocated.node.field