Skip to content

Add is_chat_creator method to ChatMemberStatus #394

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

Merged
merged 2 commits into from
Sep 13, 2020

Conversation

uburuntu
Copy link
Contributor

Add is_chat_creator method to ChatMemberStatus

Just useful check.

Type of change

  • New feature (non-breaking change which adds functionality)

How Has This Been Tested?

On my bot

@uburuntu
Copy link
Contributor Author

uburuntu commented Jul 27, 2020

Why tuples

Because they can be constant folded: https://en.wikipedia.org/wiki/Constant_folding

def f(x: int) -> bool:
    a = (1, 2, 3)
    return x in a

def g(x: int) -> bool:
    a = [1, 2, 3]
    return x in a
from dis import dis

dis(f)
  2           0 LOAD_CONST               1 ((1, 2, 3))
              2 STORE_FAST               1 (a)
  3           4 LOAD_FAST                0 (x)
              6 LOAD_FAST                1 (a)
              8 COMPARE_OP               6 (in)
             10 RETURN_VALUE
dis(g)
  6           0 LOAD_CONST               1 (1)
              2 LOAD_CONST               2 (2)
              4 LOAD_CONST               3 (3)
              6 BUILD_LIST               3
              8 STORE_FAST               1 (a)
  7          10 LOAD_FAST                0 (x)
             12 LOAD_FAST                1 (a)
             14 COMPARE_OP               6 (in)
             16 RETURN_VALUE

So lists created at every function call.

@uwinx uwinx added the enhancement Make it better! label Jul 28, 2020
Copy link
Contributor

@uwinx uwinx left a comment

Choose a reason for hiding this comment

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

👍

  • we could actually create some constant globals and use frozenset to fasten this kind of lookups, but seems like a bit over-optimization.

@uburuntu
Copy link
Contributor Author

Yea, we can use frozenset too, but on small sequences (<10-20 elements) it doesnt matter due to cache hitting.

@JrooTJunior JrooTJunior merged commit 7f05341 into aiogram:dev-2.x Sep 13, 2020
@uburuntu uburuntu deleted the admins branch September 13, 2020 22:00
uburuntu added a commit to uburuntu/aiogram that referenced this pull request Oct 4, 2020
* new: add is_chat_creator method to ChatMemberStatus

* enh: use tuples instead of lists for some checks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Make it better!
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants