Skip to content

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