Conversation
tsnoam
left a comment
There was a problem hiding this comment.
Ok... I left a review comments on the first classes. But they apply for all of the classes.
Basically, we need to cross-reference with the Telegram Bot API and make sure we don't change their semantics. (I know, a lot of work :-( ) .
That is:
- Wherever an attribute is optional - use
Noneas the default. - All attributes must be defined in the class instance (optional attributes value may be
None). That goes for int, str, bool...
And of course, unitest must pass...
telegram/audio.py
Outdated
| performer=None, | ||
| title=None, | ||
| mime_type=None, | ||
| file_size=0, |
There was a problem hiding this comment.
I wonder, should file_size be changed to default to None?
There was a problem hiding this comment.
We have that in a few places... I don't really know...
It's the same on with the booleans on Message.
telegram/audio.py
Outdated
| self.performer = performer | ||
| self.title = title | ||
| self.mime_type = str(mime_type) | ||
| if mime_type: |
There was a problem hiding this comment.
I think that it will be more accurate to use:
if mime_type is not None
But it's probably ok as it is.
There was a problem hiding this comment.
Actually nvm, I saw your comment further down ^^
telegram/chat.py
Outdated
| username=None, | ||
| first_name=None, | ||
| last_name=None, | ||
| all_members_are_admins=False, |
There was a problem hiding this comment.
I think all_members_are_admins default should be None. Using False by default changes the telegram semantics.
There was a problem hiding this comment.
Are you sure? I think maybe we should just replace all the booleans to None (regardless of what telegrams default is)
telegram/contact.py
Outdated
| """ | ||
|
|
||
| def __init__(self, phone_number, first_name, last_name='', user_id=0, **kwargs): | ||
| def __init__(self, phone_number, first_name, last_name=None, user_id=0, **kwargs): |
There was a problem hiding this comment.
I think user_id should be default to None, same reasons like with Chat above.
telegram/document.py
Outdated
| self.file_name = file_name | ||
| self.mime_type = str(mime_type) | ||
| if mime_type: | ||
| self.mime_type = str(mime_type) |
There was a problem hiding this comment.
Please make sure self.mime_type is always available. I think that this should be sufficient (no need to use str() here):
self.mime_type = mime_type
If you still think str() is required, you can do:
self.mime_type = str(mime_type) if mime_type is not None else None
This effectively removes most type checking from all optional variables... I'm not really sure that's what we want...
tsnoam
left a comment
There was a problem hiding this comment.
Wow... good job gong through all these methods.
I've pinpointed some minor changes required, also I compared the changes to the API documentation and I found some discrepencies between us, so I believe we should fix them at this chance.
One last thing, please manually merge from or rebase over master because the PR can't be merged automatically.
| username=None, | ||
| first_name=None, | ||
| last_name=None, | ||
| all_members_are_admins=None, |
There was a problem hiding this comment.
The API of Chat calls this var as all_members_are_administrators, here we use admins. Is there anything that translates admins. I think we actually have a bug here, or telegram might have silently changed the API.
There was a problem hiding this comment.
I'm about 90% sure they changed their API... so should we change it, or like keep both, or?
There was a problem hiding this comment.
We should follow their official API.
We can do bkwd-compat for a while using **kwargs.
@jh0ker What do you think?
| self.file_path = str(file_path) | ||
| self.file_size = file_size | ||
| if file_path: | ||
| self.file_path = str(file_path) |
There was a problem hiding this comment.
Just do
self.file_path = file_path
The if statement should not be there.
There was a problem hiding this comment.
Right, whoops. I removed the other ones. Seems like I missed these.
| def __init__(self, | ||
| id, | ||
| first_name, | ||
| type=None, |
There was a problem hiding this comment.
I don't see the type attribute in documentation. I think we should remove it too.
I can only guess it's something Telegram had obsoleted.
You should leave it at the prototype until ver. 7 I guess, and put a deprecation warning if it specified.
There was a problem hiding this comment.
Hmm.. I don't think it's ever been there tbh.. I might be us who made an error and confused User for Chat or something.
There was a problem hiding this comment.
I think Telegram removed it.
@jh0ker what do you think?
There was a problem hiding this comment.
I think I remember it from the official docs as well, but I could be wrong...
| has_custom_certificate, | ||
| pending_update_count, | ||
| last_error_date=None, | ||
| last_error_message=None, |
There was a problem hiding this comment.
We're missing optionals: max_connections (int) & allowed_updates (List[str])
There was a problem hiding this comment.
I thought that too, so I checked the official December 4th release notes and it wasn't there, so lets fix it here while we're at it.
Should remove all cases of having empty strings returned from to_dict (if I didn't miss any).
Closes #460