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
Review types of optional arguments in methods and classes #3864
Comments
I did some investigation on this. First, regarding arguments of bot methods: Let's take Moreover, I collected all arguments in our code base with one of these type hints: Scriptimport re
from pathlib import Path
from pprint import pprint
REGEX = re.compile(r"\s([_\w]+: O?DV(Input|Type)\[\w+\] = .*)")
MATCHES = set()
for file_path in Path("telegram").rglob("*.py"):
content = file_path.read_text(encoding="utf-8")
for match in REGEX.finditer(content):
MATCHES.add(match.group(1))
pprint(sorted(MATCHES)) Results: ['allow_sending_without_reply: DVInput[bool] = DEFAULT_NONE,',
'allow_sending_without_reply: ODVInput[bool] = DEFAULT_NONE,',
'block: DVType[bool] = DEFAULT_TRUE,',
'connect_timeout: ODVInput[float] = BaseRequest.DEFAULT_NONE,',
'connect_timeout: ODVInput[float] = DEFAULT_NONE,',
'disable_notification: DVInput[bool] = DEFAULT_NONE,',
'disable_notification: ODVInput[bool] = DEFAULT_NONE,',
'disable_web_page_preview: ODVInput[bool] = DEFAULT_NONE,',
'explanation_parse_mode: ODVInput[str] = DEFAULT_NONE,',
'parse_mode: ODVInput[str] = DEFAULT_NONE,',
'pool_timeout: ODVInput[float] = BaseRequest.DEFAULT_NONE,',
'pool_timeout: ODVInput[float] = DEFAULT_NONE,',
'protect_content: ODVInput[bool] = DEFAULT_NONE,',
'read_timeout: ODVInput[float] = BaseRequest.DEFAULT_NONE,',
'read_timeout: ODVInput[float] = DEFAULT_NONE,',
'write_timeout: ODVInput[float] = 20,',
'write_timeout: ODVInput[float] = BaseRequest.DEFAULT_NONE,',
'write_timeout: ODVInput[float] = DEFAULT_NONE,'] In this, I see several notable points. Firstly, we have inconsistencies in the typing of Thirdly, there is a problem with python-telegram-bot/telegram/request/_httpxrequest.py Lines 177 to 200 in a0decda
this leads to My first idea would be the following:
This would be a backward compatible change, further decouple the What do you think? |
this commit fixes documentation
can you assign this to me please . |
@UjjwalPardeshi this issue is still in discussion and not ready to be pred for |
Shouldn't that be higher? Your logic looks sound to me. Would go ahead. |
kinda shocking that this went unnoticed by tests and everyone (maybe that's why ppl keep posting the timeout errors even after changing the timeout vals)
We would also need to add a new method to AppBuilder for the new arg right?
Idea sounds good 👍🏽
I agree, should be like 30 seconds min to accomodate for slower internet speeds (https://www.speedtest.net/global-index) |
Actually I'm backtracking on adding if write_timeout is not DEFAULT_NONE:
effective_write_timeout = write_timeout
elif files:
effective_write_timeout = 30
else:
effective_write_timeout = self.write_timeout We would continue to document in the send_* methods that the write_timeout param defaults to 30 seconds. |
20 is the value that has been used for eons (minimum since v6.0) and is documented everywhere. If there are no clear indications that this value is too short for most people, I would prefer to stick to the 20 …
yes, of course
Just to clarify: This would steeps 1 & 3, only step 2 would be omitted. |
@Bibo-Joshi 20 seconds is a sane default. We worked it out the hard way. It is a trade off between identifying problems asap and between being too aggressive and/or slow internet connections. The default should not be supportive of those with horrible internet. |
ok, but tbf I've only ever seen people increase the timeouts, not decrease them.
Right, I was thinking
👍🏽 |
ALl right, then I think we have a consensus here and there are 3 PRs to be done:
|
@Bibo-Joshi you’ve out seen those who complained. Think of all those which it worked good for them. Increasing the timeout by default will change the behavior and raise a wave of complaints. However, that said and ptb is in a differed state today. It is using httpx which greatly superior to urllib3 and all the alternatives available back at the day. |
If you want something which controls the timeouts in a smarter way it might be a good idea to check what is the payload size to send and decide on the timeout accordingly |
There are certain parameters in our bot methods which optional with the default as
DEFAULT_NONE
(as specified by theDefaults
class). The type hinting of such parameters is not consistent. For e.g.python-telegram-bot/telegram/_bot.py
Line 7197 in 8cc55c3
and
python-telegram-bot/telegram/_bot.py
Line 7201 in 8cc55c3
both parameters accept
bool
, but one of them is type hinted to also acceptNone
(ODV -> Optional DefaultValue). Here the type hint forprotect_content
should be corrected toDVInput
imo.We should look for other cases like this, and correct it in both the type hints and documentation.
The text was updated successfully, but these errors were encountered: