X Tutup
Skip to content

No empty strings in to_dict#494

Merged
jh0ker merged 6 commits intomasterfrom
fix-460
Feb 27, 2017
Merged

No empty strings in to_dict#494
jh0ker merged 6 commits intomasterfrom
fix-460

Conversation

@jsmnbom
Copy link
Copy Markdown
Member

@jsmnbom jsmnbom commented Dec 30, 2016

Should remove all cases of having empty strings returned from to_dict (if I didn't miss any).

Closes #460

Copy link
Copy Markdown
Member

@tsnoam tsnoam left a comment

Choose a reason for hiding this comment

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

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 None as 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...

performer=None,
title=None,
mime_type=None,
file_size=0,
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I wonder, should file_size be changed to default to None?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

We have that in a few places... I don't really know...
It's the same on with the booleans on Message.

self.performer = performer
self.title = title
self.mime_type = str(mime_type)
if mime_type:
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think that it will be more accurate to use:
if mime_type is not None
But it's probably ok as it is.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I'mma fix it anyways :)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

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,
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think all_members_are_admins default should be None. Using False by default changes the telegram semantics.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Are you sure? I think maybe we should just replace all the booleans to None (regardless of what telegrams default is)

"""

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):
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think user_id should be default to None, same reasons like with Chat above.

self.file_name = file_name
self.mime_type = str(mime_type)
if mime_type:
self.mime_type = str(mime_type)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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...
Copy link
Copy Markdown
Member

@tsnoam tsnoam left a comment

Choose a reason for hiding this comment

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

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,
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I'm about 90% sure they changed their API... so should we change it, or like keep both, or?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

We should follow their official API.
We can do bkwd-compat for a while using **kwargs.
@jh0ker What do you think?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I'd say we keep bkwd-compat

self.file_path = str(file_path)
self.file_size = file_size
if file_path:
self.file_path = str(file_path)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Just do
self.file_path = file_path
The if statement should not be there.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Right, whoops. I removed the other ones. Seems like I missed these.

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

Choose a reason for hiding this comment

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

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.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

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.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think Telegram removed it.
@jh0ker what do you think?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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,
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

We're missing optionals: max_connections (int) & allowed_updates (List[str])

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I noticed but I thought @jh0ker was working on that?
Now that I look at it, it doesn't seem to be in our PR list... (I think I confused it for #483)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Wait no... it totally is part of #483 isn't it, @jh0ker?

@jh0ker jh0ker merged commit e69e99c into master Feb 27, 2017
jh0ker added a commit that referenced this pull request Feb 27, 2017
jh0ker added a commit that referenced this pull request Feb 27, 2017
jh0ker added a commit that referenced this pull request Feb 27, 2017
@jsmnbom jsmnbom deleted the fix-460 branch May 20, 2017 13:50
@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.

User.to_dict() returns absent fields with empty strings '' values

3 participants

X Tutup