Skip to content

Simplify code #3

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 3 commits into from
Jul 11, 2015
Merged

Conversation

JASON0916
Copy link
Contributor

Git is so hard for me. I add '.gitignore' and '.idea/' to .gitignore but it doesn't work, so i delete it directly orz.
I found that most [send*() functions] like sendVideo(), sendsticker() ... are similar, can we simplify them by decorator ?

@leandrotoledo
Copy link
Member

Hey Jason, thanks for your pull request!
So, I've tested your code and sometimes it's crashing because dicts don't keep orders when insertions may occur (so data.keys()[1] won't be always what you want):

Testing sendAudio - File

/home/leandrotoledo/workspace/python-telegram/telegram/bot.py(608)_requestUrl()
-> if len(data) >= 2 and data.keys()[1] in file_type and
(Pdb) len(data)
2
(Pdb) data.keys()[1] in file_type
False
(Pdb) data.keys()
'audio', 'chat_id' data.keys()[1]
'chat_id'

You can try something like:

def _isfilerequest(self,
                   data=None):
    if data:
        file_types = ['audio', 'document', 'photo', 'video']
        file_type = [i for i in data.keys() if i in file_types]

        if file_type:
            file_content = data[file_type[0]]
            ...

    return False

@leandrotoledo
Copy link
Member

Great idea about decorators!

@JASON0916
Copy link
Contributor Author

Your method seems to be much better, i will try. I didn't imagine problem like that. T^T Thanks for your test and review!

@leandrotoledo
Copy link
Member

All tests passed right away! Yay. I'm merging your pull request.

Thank you very much! :)

leandrotoledo added a commit that referenced this pull request Jul 11, 2015
@leandrotoledo leandrotoledo merged commit 2e7e24d into python-telegram-bot:master Jul 11, 2015
@JASON0916 JASON0916 deleted the simplify-code branch July 12, 2015 05:05
jeffffc pushed a commit to jeffffc/python-telegram-bot that referenced this pull request May 9, 2018
@github-actions github-actions bot locked and limited conversation to collaborators Aug 26, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy