User like properties#4713
Conversation
…as in the `telegram.User` class.
…sts for it; Replace `user` and `shared_user` correspond properties implementations on a new functinos.
…rnames.py` implementation; Note: `full_name` and `effective_name` can not be easily replaced in the such way
…lved; Slots tests failed for Protocol class.
Bibo-Joshi
left a comment
There was a problem hiding this comment.
Thanks for the updates! I had just a very quick look so far
- I'm not sure if I have used overloads correctly, as warnings are still present.
I don't see anything wrong at first glance, but haven't seen the mypy warnings (pre-commit truncated the output). Looking up other code, have a look at
python-telegram-bot/telegram/_utils/argumentparsing.py
Lines 71 to 94 in 1503287
for how Protocol and typevar are used there. maybe that helps.
- There is a failed slots test for the class.
in the above code section the if TYPE_CHECKING ensures that the class is not defined at test runtime. this would get the test passing.
- Is it necessary to test the properties of the User class, or utils.usernames is sufficient to test ?
I'd say testing the properties of the User(/Chat/SharedUser) class is enough and explicitly testing _utils.usernames is not required :)
Please also install the pre-commit hooks
| # You should have received a copy of the GNU Lesser Public License | ||
| # along with this program. If not, see [http://www.gnu.org/licenses/]. | ||
| """Shared properties to extract username, first_name, last_name values if filled.""" | ||
| from __future__ import annotations |
There was a problem hiding this comment.
please avoid using this. If this is for using |, please use Union and Optional instead
| unlike the `Chat` and `Shared`, were they are optional. | ||
| The `last_name` is always optional. | ||
| """ | ||
| last_name: str | None |
There was a problem hiding this comment.
| last_name: str | None | |
| first_name: Optional[str] | |
| last_name: str | None |
that way you should be able to remove MiniUserLike
There was a problem hiding this comment.
- One of the hooks, probably black or isort, converts automatically during commit.
- Sometimes, the field always exists (for example, for the
Usertype) and sometimes it might not (like in theSharedUsertype). This affects the return type: it can beOptional[str]or guaranteed to be anstr. That's why I introduced it. - I know the name
MiniUserLikeis pretty silly, but I couldn't think of anything better. I hope you can help me with that :)
There was a problem hiding this comment.
- running the pre-commit hooks on python 3.9 (lowest supported version) should make sure that this doesn't happen. Though I admit I'm not completely sure why it does in the first place
- you already differentiate between
UserLikeOptionalandUserLike. That should already do the trick IMO
|
@david-shiko are you still interested in finishing this up? |
Hi, yes, I'm interested, but I don't have any free time and I don't know when it will be, you can close it, and if anything, I'll make a new PR or open this one. |
|
Closing in favor of #4881, which i based on this. Thanks @david-shiko for the early efforts. |
This is a basic implementation of the changes suggested in the pull request 4708 .
Please note that there are several issues with the code:
Userclass, orutils.usernamesis sufficient to test ?