Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Docs update #728

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 28 commits into from
Jul 23, 2017
Merged

Docs update #728

merged 28 commits into from
Jul 23, 2017

Conversation

Eldinnie
Copy link
Member

@Eldinnie Eldinnie commented Jul 19, 2017

So here it is. All new and unified docs.
There might be some small spelling errors (if you find them please notify me).
It's a moloch of a pull request but I already included latest master (and updated the docstrings for new methods).

Eldinnie added 12 commits June 26, 2017 23:43
WebhookInfo

User
UserProfilePhotos
WebhookInfo

Update
User
UserProfilePhotos
WebhookInfo

ReplyKeyboardRemove

ReplyKeyboardRemove small typo

ReplyKeyboardMarkup

MessageEntity

Message

KeyboardButton

ForceReply

Errors

Constants

ChosenInlineResult

ChatMember

ChatAction

MessageEntity.rst

Chat

CallbackQuery

Base
unicode characters
Copy paste from bot api website copied some unicode characters that made tests fail on python 2.7
Remove type from user tests
Animation
CallbackGame
Game
GameHighscore
Invoice
LabeledPrice
OrderInfo
PreCheckoutQuery
ShippingAddress
ShippingOption
ShippingQuery
SuccessfulPayment
InlineKeyboardButton
InlineKeyboardMarkup
InlineQuery
InlineQueryResult
InlineQueryResultArticle

InlineQueryResultAudio
InlineQueryResultArticle
InlineQueryResultAudio
InlineQueryResultCachedAudio
InlineQueryResultCachedDocument
InlineQueryResultCachedGif
InlineQueryResultCachedMpeg4Gif
InlineQueryResultCachedPhoto
InlineQueryResultCachedSticker
InlineQueryResultCachedVideo
InlineQueryResultCachedVoice
InlineQueryResultContact
InlineQueryResultDocument
InlineQueryResultGame
InlineQueryResultGif
InlineQueryResultLocation
InlineQueryResultMpeg4Gif
InlineQueryResultPhoto
InlineQueryResultVenue
InlineQueryResultVideo
InlineQueryResultVoice
InputContactMessageContent
InputLocationMessageContent
InputMessageContent
InputTextMessageContent
InputVenueMessageContent
Audio
Contact
Document
File
InputFile
Location
PhotoSize
Sticker
Venue
Video
VideoNote
Voice
Files
CommandHandler
InlineQueryHandler
MessageHandler
ChosenInlineResultHandler
PreCheckoutQueryHandler
Regexhandler
- Also modified the check_update part for this.
TypeHandler
StringRegexHandler
StringCommandHandler
ShippingQueryHandler
Handler
ConversationHandler
Updated all new docs in new style
Filters
Dispatcher
JobQueue
Updater
MessageQueue
@rahiel
Copy link
Contributor

rahiel commented Jul 19, 2017

In #726 I added a note on where to find the max message length in bot.send_message, this is absent from this PR.

@Eldinnie
Copy link
Member Author

@rahiel Because Max message length is now in the docstring for every text message method

This was referenced Jul 19, 2017
@Eldinnie
Copy link
Member Author

Regarding the questions @bomjacob asked:

  1. When we have an arg like: Arg (type): Text. Should Text then be Text or text (aka start with a capital letter)?. It's not quite consistent (and fairly easy to fix with a regex replace if we just decide on a preferred style.
    A: IMO yes, always capitals at the start of sentences. I'll run a check I thought I had them all.

  2. Is there any way to inherit docstrings? (thinking about handlers and such, which have a lot of repetition in their handle_ and check_ and such)
    A: There might be. But atm we've got them all covered.

  3. Should we give all the callbacks a set type too? (if it's even possible?) Typing using Callable[[Arg1Type, Arg2Type], ReturnType] but I'm not sure sphinx understands that.
    A: Function is also a type (or maybe change to callable).

  4. There are ALOT of places where we have args and attributes that are almost exactly the same... Could we figure out a better way to write that? Cause I don't think it looks very good to just have everything be copy pasted everywhere... Maybe like use args if the user is meant to instantiate it themselves only?
    A: The docs describe the objects. And for most of our objects, it's attributes are the same as their constructing arguments. Hence they're both in the docs. Pro is that the roolsbot can link to attributes, but not to arguments. I tried to make the attributes more descriptive of what it is, and the arguments more defining what is expected when constructing. Maybe I can edit this more to make the attributes more compact.

  5. According to napoleon's google docstring format example optional arguments should be like: param2 (:obj:'int', optional): Description of 'param2'. Multiple lines are supported. and not param2 (Optional[:obj:'int']): Description of 'param2'. Multiple lines are supported. like we're using atm. (just pretend those ' are ... github is being annyoing.) Should we fix that? (I personally like the first style better) (if we decide on the latter we should figure out of the o in optional should be capital or not) A: I followed the way it was done in bot.py` (Optional[str]). I have no problem converting it to the styleguide. A lot of extra work though

  6. Also in line with the above, is there a convention for when to use :obj'int' and when to use just int? It seems we don't use the :obj: notation anywhere? Should we?
    A: The style guide give both options. It doesn't really matter much as long as it is consequent. I think I made it consequent.

  7. It also uses :obj:'list' of :obj:'str' instead of List[str]. I personally think that in this case the latter looks a whole lot better. But I'm not sure if napoleon parses it differently?
    A: I changed all List[str] to list(str) and napoleon parses them fine. It looks to most natural and pythonic to me.

  8. After a while I stopped commenting about square brackets. (I've since removed those comments in favour of this note.) Is there a reason you're replacing them all? I'm not necessarily against it, I just want a reason since I personally think square brackets look better. It also seems a bit inconsistent between args and attributes sections (see InlineKeyboardMarkup). It seems you use [] to signify a list in attributes section but not in args?
    A: Also see answer in 7, but in attributes brackets are parsed differently than in arguments. I tried to find a style that would look best and readable on both sections. Also I made it consequent. But again a good overhaul to the style guide might be best option.

@jsmnbom
Copy link
Member

jsmnbom commented Jul 19, 2017

  1. :D

  2. Alright, this works for now then.

  3. Yeah maybe change to callable :)

  4. Hmm, I guess it's fine for now... just felt that there was a lot of bulk when you look through the code, which I'm not a fan of :/

  5. I personally prefer the styleguide way of doing things... We should probably ask others though. @python-telegram-bot/developers Any preferences? I'm honestly not even sure where the Optional[type] notation comes from :/

  6. Alright sounds good :)

  7. and 8.
    This is where we disagree :) I prefer we used much the same notation as is used in typing since that seems like the "official" python way to do type declarations to me. This means using List[type] and Tuple[type]. Once again asking @python-telegram-bot/developers :)
    However with that being said, I think using parenthesis looks alright too. I do not like how the syntax is different between the Args and Attributes sections... Imo, if we need to have them both, they should most certainly have the same type declarations. It's not very user (as in us developers) friendly to have square brackets mean 2 different things (Optional[type] and [str], first one meaning it's optional and the second one meaning it's a list).

@Eldinnie
Copy link
Member Author

I wasn't know with the typing stuff. Now I've seen it I aggree on 7 and 8. Will make try how it looks.

All classes and methods now use the google style guide for docstrings.
Copy link
Member

@jsmnbom jsmnbom left a comment

Choose a reason for hiding this comment

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

Okay that should be my last comments as far as docstring and code goes (haven't looked at rst files since you said those weren't done yet.

I know it looks like a butt-ton of comments, but most of them are fairly trivial :)

telegram/bot.py Outdated
chat_id (:obj:`int` | :obj:`float`): Unique identifier for the target chat or username
of the target channel (in the format @channelusername).
text (:obj:`str`): Text of the message to be sent. Max 4096 characters. Also found as
``telegram.constants.MAX_MESSAGE_LENGTH``.
Copy link
Member

Choose a reason for hiding this comment

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

:const:`telegram.constants.MAX_MESSAGE_LENGTH`
(also found elsewhere, search for "4096")

telegram/bot.py Outdated
@channelusername).
message_id (int): Unique message identifier.
timeout (Optional[int|float]): If this value is specified, use it as the read timeout
chat_id (:obj:`int` | :obj:`float`): Unique identifier for the target chat or username
Copy link
Member

Choose a reason for hiding this comment

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

I think you mean :obj:`int` | :obj:`str`
(also applies elsewhere)

telegram/bot.py Outdated
"""As of v.4.0, Telegram clients support rounded square mp4 videos of up to 1 minute
long. Use this method to send video messages
"""
As of v.4.0, Telegram clients support rounded square mp4 videos of up to 1 minute long.
Copy link
Member

Choose a reason for hiding this comment

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

The first line should describe what the method does. Either flip around the lines or in this case simply remove it.

telegram/bot.py Outdated
action(:class:`telegram.ChatAction` | :obj:`str`): Type of action to broadcast. Choose
one, depending on what the user is about to receive:

* typing for text messages
Copy link
Member

Choose a reason for hiding this comment

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

The constants are preferred here I'd say

Copy link
Member Author

Choose a reason for hiding this comment

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

The method doesn't care, so I put it this way.

Copy link
Member

Choose a reason for hiding this comment

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

I would very very much like to encourage our users to use the constants though

Copy link
Member Author

Choose a reason for hiding this comment

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

Changed doc to remove the list from this method and point to ChatAction

telegram/base.py Outdated
@@ -84,7 +76,7 @@ def to_dict(self):
def __eq__(self, other):
if isinstance(other, self.__class__):
return self._id_attrs == other._id_attrs
return super(TelegramObject, self).__eq__(other)
return super(TelegramObject, self).__eq__(other) # pylint: disable=E1101
Copy link
Member

Choose a reason for hiding this comment

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

Could you maybe use the new named pylint names instead of the id?
# pylint: disable=no-member

Copy link
Member Author

Choose a reason for hiding this comment

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

imo out of scope.

Copy link
Member

Choose a reason for hiding this comment

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

Out of scope of this PR? You added the comment though... I'm not asking you to go back and find all our pylint lines, I'm just thinking that we should start slowly switching over so we make it easier for ourselves in the future.

Copy link
Member Author

Choose a reason for hiding this comment

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

you're right (forgot I put this in)

"""

def __init__(self,
id,
first_name,
type=None,
Copy link
Member

Choose a reason for hiding this comment

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

This means that we break backwards compat doesn't it?

Copy link
Member Author

Choose a reason for hiding this comment

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

users are created by tg which does not send type. So I guess not

Copy link
Member

Choose a reason for hiding this comment

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

We still technically do though... @tsnoam thoughts?

Copy link
Member Author

Choose a reason for hiding this comment

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

It does not break tests and users have no type, so I see no problem in just removing it. It's still captured with **kwargs if needed.



class TypeHandler(Handler):
"""
Handler class to handle updates of custom types.

Attributes:
type (:obj:`class`): The ``type`` of updates this handler should process.
Copy link
Member

Choose a reason for hiding this comment

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

Shouldn't that be of type type?

Copy link
Member Author

Choose a reason for hiding this comment

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

It's a bit of a weird handler. You use it like:

import InlineQuery
add_handler(TypeHandler(InlineQuery))

Copy link
Member

Choose a reason for hiding this comment

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

Exactly you pass it a class which has the type type

>>> class Test:
...     pass
...
>>> type(Test)
<class 'type'>
>>>

Copy link
Member Author

Choose a reason for hiding this comment

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

Oh! ok, will change

Args:
latitude (:obj:`float`): Latitude of the location in degrees.
longitude (:obj:`float`): Longitude of the location in degrees.
title (:obj:`str`); Name of the venue.
Copy link
Member

Choose a reason for hiding this comment

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

Semi colon?
(also applies elsewhere (a search for ; is fairly quick)

selective (:obj:`bool`, optional): Use this parameter if you want to force reply from
specific users only. Targets:

1) users that are @mentioned in the text of the Message object;
Copy link
Member

Choose a reason for hiding this comment

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

Remove semi colon

shipping_query (:class:`telegram.ShippingQuery`): New incoming shipping query.
pre_checkout_query (:class:`telegram.PreCheckoutQuery`): New incoming pre-checkout query.
Note:
At most one of the optional parameters can be present in any given update.
Copy link
Member

Choose a reason for hiding this comment

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

  • "With the exception of update_id which is always present."

Copy link
Member Author

Choose a reason for hiding this comment

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

that's why it's "at most one of the optional parameters..."

@Eldinnie
Copy link
Member Author

I addressed all matter @bomjacob mentioned. IMO it's ready for merge @tsnoam or @jh0ker

@@ -44,7 +44,7 @@ class PreCheckoutQueryHandler(Handler):
or in the same chat, it will be the same ``dict``.

Args:
callback (:obj:`callable): A function that takes ``bot, update`` as positional arguments.
callback (:obj:`callable'): A function that takes ``bot, update`` as positional arguments.
Copy link
Member

@jsmnbom jsmnbom Jul 23, 2017

Choose a reason for hiding this comment

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

Is that a ' instead of `?

@@ -27,7 +27,8 @@ class InlineKeyboardButton(TelegramObject):
This object represents one button of an inline keyboard.

Note:
You must use exactly one of the optional fields.
You must use exactly one of the optional fields. Mind that :attr:`callback_game` is not
Copy link
Member

Choose a reason for hiding this comment

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

This isn't true though. callback_game the attribute is implemented, but it just accepts a games short name I think, otherwise there would be no way to launch games from custom keyboards.

@Eldinnie Eldinnie added the 📋 pending-merge work status: pending-merge label Jul 23, 2017
Eldinnie added 4 commits July 23, 2017 15:42
restored old order of kwargs in regexhandler
added deprecation warning
Parameter to StickerSet was flasely named on TG's docs as is_masks. It's fixed now.
@tsnoam tsnoam removed the 📋 pending-merge work status: pending-merge label Jul 23, 2017
Eldinnie and others added 4 commits July 23, 2017 21:51
 Conflicts:
	CHANGES.rst
	telegram/base.py
	telegram/bot.py
	telegram/callbackquery.py
	telegram/chat.py
	telegram/chatmember.py
	telegram/choseninlineresult.py
	telegram/files/audio.py
	telegram/files/chatphoto.py
	telegram/files/contact.py
	telegram/files/document.py
	telegram/files/file.py
	telegram/files/location.py
	telegram/files/photosize.py
	telegram/files/sticker.py
	telegram/files/video.py
	telegram/files/videonote.py
	telegram/files/voice.py
	telegram/forcereply.py
	telegram/games/animation.py
	telegram/games/game.py
	telegram/games/gamehighscore.py
	telegram/inline/inlinekeyboardbutton.py
	telegram/inline/inlinekeyboardmarkup.py
	telegram/inline/inlinequery.py
	telegram/message.py
	telegram/messageentity.py
	telegram/payment/invoice.py
	telegram/payment/labeledprice.py
	telegram/payment/orderinfo.py
	telegram/payment/precheckoutquery.py
	telegram/payment/shippingaddress.py
	telegram/payment/shippingoption.py
	telegram/payment/shippingquery.py
	telegram/payment/successfulpayment.py
	telegram/replykeyboardmarkup.py
	telegram/replykeyboardremove.py
	telegram/replymarkup.py
	telegram/update.py
	telegram/user.py
	telegram/userprofilephotos.py
	telegram/webhookinfo.py
@tsnoam tsnoam merged commit b3b9424 into master Jul 23, 2017
@tsnoam tsnoam deleted the docs_update branch July 23, 2017 20:33
@github-actions github-actions bot locked and limited conversation to collaborators Aug 23, 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.

4 participants