Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

User like properties#4713

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
david-shiko wants to merge4 commits intopython-telegram-bot:master
base:master
Choose a base branch
Loading
fromdavid-shiko:UserLikeProperties

Conversation

david-shiko
Copy link
Contributor

@david-shikodavid-shiko commentedMar 10, 2025
edited
Loading

This is a basic implementation of the changes suggested in thepull request 4708 .

Please note that there are several issues with the code:

  1. I'm not sure if I have used overloads correctly, as warnings are still present.
  2. There is a failed slots test for the class.
  3. Is it necessary to test the properties of theUser class, orutils.usernames is sufficient to test ?

…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
Copy link
Member

@Bibo-JoshiBibo-Joshi left a comment

Choose a reason for hiding this comment

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

Thanks for the updates! I had just a very quick look so far

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

Tele_co=TypeVar("Tele_co",bound=TelegramObject,covariant=True)
TeleCrypto_co=TypeVar("TeleCrypto_co",bound="HasDecryptMethod",covariant=True)
ifTYPE_CHECKING:
@type_check_only
classHasDecryptMethod(Protocol):
__slots__= ()
@classmethod
defde_json_decrypted(
cls:type[TeleCrypto_co],
data:JSONDict,
bot:Optional["Bot"],
credentials:list["FileCredentials"],
)->TeleCrypto_co: ...
@classmethod
defde_list_decrypted(
cls:type[TeleCrypto_co],
data:list[JSONDict],
bot:Optional["Bot"],
credentials:list["FileCredentials"],
)->tuple[TeleCrypto_co, ...]: ...

for how Protocol and typevar are used there. maybe that helps.

  1. There is a failed slots test for the class.

in the above code section theif TYPE_CHECKING ensures that the class is not defined at test runtime. this would get the test passing.

  1. 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 thepre-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
Copy link
Member

Choose a reason for hiding this comment

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

please avoid using this. If this is for using|, please useUnion andOptional instead

unlike the `Chat` and `Shared`, were they are optional.
The `last_name` is always optional.
"""
last_name: str | None
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
last_name:str|None
first_name:Optional[str]
last_name:str|None

that way you should be able to removeMiniUserLike

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

  1. One of the hooks, probably black or isort, converts automatically during commit.
  2. Sometimes, the field always exists (for example, for theUser type) and sometimes it might not (like in theSharedUser type). This affects the return type: it can beOptional[str] or guaranteed to be anstr . That's why I introduced it.
  3. I know the nameMiniUserLike is pretty silly, but I couldn't think of anything better. I hope you can help me with that :)

Copy link
Member

Choose a reason for hiding this comment

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

  • 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 betweenUserLikeOptional andUserLike. That should already do the trick IMO

@Bibo-Joshi
Copy link
Member

@david-shiko are you still interested in finishing this up?

@david-shiko
Copy link
ContributorAuthor

@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.

Bibo-Joshi reacted with thumbs up emoji

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@Bibo-JoshiBibo-JoshiBibo-Joshi requested changes

Requested changes must be addressed to merge this pull request.

Assignees
No one assigned
Labels
None yet
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

2 participants
@david-shiko@Bibo-Joshi

[8]ページ先頭

©2009-2025 Movatter.jp