Skip to content

Dropping non context #2617

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 17 commits into from
Aug 29, 2021
Merged

Dropping non context #2617

merged 17 commits into from
Aug 29, 2021

Conversation

Poolitzer
Copy link
Member

This PR drops all non context based code. It also removes the regex handler (because it had non context code in it and just removing that one from the handler which was going to be removed anyway felt unnecessary).

@Poolitzer
Copy link
Member Author

Poolitzer commented Aug 4, 2021

The tests will fail. I have no clue about mypy (help pls) and my internet connection is too unstable rn to run pytest, so I am going to use the CI results to fix the remaining tests.

telegram/ext/handler.py:144: error: Argument 1 to "collect_additional_context" of "Handler" has incompatible type "Optional[CCT]"; expected "CCT"  [arg-type]
telegram/ext/handler.py:147: error: Argument 2 has incompatible type "Optional[CCT]"; expected "CCT"  [arg-type]
telegram/ext/conversationhandler.py:645: error: Argument 4 to "_schedule_job" of "ConversationHandler" has incompatible type "Optional[CallbackContext[Any, Any, Any]]"; expected "CallbackContext[Any, Any, Any]"  [arg-type]

@Poolitzer
Copy link
Member Author

Apart from the mypy errors mentioned above which I do not understand, I also dont understand this pytest error, all others pass \o/

__________________ TestDispatcher.test_one_context_per_update __________________

self = <tests.test_dispatcher.TestDispatcher object at 0x7f90e4361898>
dp = <telegram.ext.dispatcher.Dispatcher object at 0x7f90e50fcd90>

    def test_one_context_per_update(self, dp):
        def one(update, context):
            if update.message.text == 'test':
                context.my_flag = True
    
        def two(update, context):
            if update.message.text == 'test':
                if not hasattr(context, 'my_flag'):
                    pytest.fail()
            else:
                if hasattr(context, 'my_flag'):
                    pytest.fail()
    
        dp.add_handler(MessageHandler(Filters.regex('test'), one), group=1)
        dp.add_handler(MessageHandler(None, two), group=2)
        u = Update(1, Message(1, None, None, None, text='test'))
>       dp.process_update(u)

tests/test_dispatcher.py:142: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
telegram/ext/dispatcher.py:538: in process_update
    handler.handle_update(update, self, check, context)
telegram/ext/handler.py:147: in handle_update
    return self.callback(update, context)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

update = <telegram.update.Update object at 0x7f90e4248e88>
context = <telegram.ext.callbackcontext.CallbackContext object at 0x7f90e40d89a8>

    def two(update, context):
        if update.message.text == 'test':
            if not hasattr(context, 'my_flag'):
>               pytest.fail()
E               Failed

tests/test_dispatcher.py:134: Failed

@Bibo-Joshi Bibo-Joshi mentioned this pull request Aug 10, 2021
22 tasks
Copy link
Member

@Bibo-Joshi Bibo-Joshi left a comment

Choose a reason for hiding this comment

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

Overall looks good! A few notes:

  • Searching for use_context in the branch still gives a number of results - please make sure to remove those
  • I only skimmed the tests, but I'm sure they are fine :)
  • Coverage decrease: Codecov marked nothing as untested that was tested before, IISC. I guess the decrease is just due to the fact that we're removing a lot of testing lines here so that the percentage of untested lines increases …

@Bibo-Joshi
Copy link
Member

👍
Just saw that most docstrings for callback arguments say something like Callback signature for context based API. I guess we can simplify that now …

Copy link
Member Author

@Bibo-Joshi True, good point

Copy link
Member

@harshil21 harshil21 left a comment

Choose a reason for hiding this comment

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

noticed that regexhandler needs to be removed from telegram.ext.rst too. Skimmed through the rest, seems fine.

Poolitzer: Grrr, I swear I searched for regexhandler in the project

@harshil21 harshil21 added this to the v14 milestone Aug 13, 2021
@harshil21 harshil21 added the 🛠 breaking change type: breaking label Aug 13, 2021
@Poolitzer
Copy link
Member Author

I tried fixing the merge conflicts but I might have broken everything :(

Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

Hey there. Relax, I am just a little warning for the maintainers to release directly after merging your PR, otherwise we have broken examples and people might get confused :)

# Conflicts:
#	tests/test_dispatcher.py
#	tests/test_persistence.py
@Bibo-Joshi Bibo-Joshi force-pushed the dropping_non_context branch from b319bae to 6959ae3 Compare August 19, 2021 17:32
@Bibo-Joshi
Copy link
Member

sorry to be bummer, but I think you were a little too thorough with your last doc change. IMO we should still state how the signature of the callback looks like, either by writing def callback(…) or just writing something like "the callback must be callable with two positional arguments of type Update and CallbackContext, respectively". What I meant was that we can skip the "for context based API" part, is there is no different API anymore now :)

@Poolitzer
Copy link
Member Author

Hmm. Yeah I guess you are right, no way to know this without looking at the wiki.

Poolitzer and others added 2 commits August 27, 2021 15:16
# Conflicts:
#	telegram/ext/handler.py
#	telegram/ext/jobqueue.py
#	tests/test_callbackcontext.py
#	tests/test_callbackqueryhandler.py
#	tests/test_chatmemberhandler.py
#	tests/test_inlinequeryhandler.py
#	tests/test_messagehandler.py
#	tests/test_pollanswerhandler.py
#	tests/test_pollhandler.py
#	tests/test_precheckoutqueryhandler.py
#	tests/test_regexhandler.py
#	tests/test_shippingqueryhandler.py
#	tests/test_stringcommandhandler.py
#	tests/test_stringregexhandler.py
#	tests/test_typehandler.py
@Bibo-Joshi Bibo-Joshi merged commit a32851a into v14 Aug 29, 2021
@Bibo-Joshi Bibo-Joshi deleted the dropping_non_context branch August 29, 2021 16:15
@github-actions github-actions bot locked and limited conversation to collaborators Aug 30, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
🛠 breaking change type: breaking
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants