Skip to content

Remove builtin names where possible #1792

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 1 commit into from
Feb 23, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions telegram/ext/picklepersistence.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,12 +81,12 @@ def load_singlefile(self):
try:
filename = self.filename
with open(self.filename, "rb") as f:
all = pickle.load(f)
self.user_data = defaultdict(dict, all['user_data'])
self.chat_data = defaultdict(dict, all['chat_data'])
data = pickle.load(f)
self.user_data = defaultdict(dict, data['user_data'])
self.chat_data = defaultdict(dict, data['chat_data'])
# For backwards compatibility with files not containing bot data
self.bot_data = all.get('bot_data', {})
self.conversations = all['conversations']
self.bot_data = data.get('bot_data', {})
self.conversations = data['conversations']
except IOError:
self.conversations = {}
self.user_data = defaultdict(dict)
Expand All @@ -110,9 +110,9 @@ def load_file(self, filename):

def dump_singlefile(self):
with open(self.filename, "wb") as f:
all = {'conversations': self.conversations, 'user_data': self.user_data,
'chat_data': self.chat_data, 'bot_data': self.bot_data}
pickle.dump(all, f)
data = {'conversations': self.conversations, 'user_data': self.user_data,
'chat_data': self.chat_data, 'bot_data': self.bot_data}
pickle.dump(data, f)

def dump_file(self, filename, data):
with open(filename, "wb") as f:
Expand Down
36 changes: 18 additions & 18 deletions tests/test_callbackquery.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

@pytest.fixture(scope='class', params=['message', 'inline'])
def callback_query(bot, request):
cbq = CallbackQuery(TestCallbackQuery.id,
cbq = CallbackQuery(TestCallbackQuery.id_,
TestCallbackQuery.from_user,
TestCallbackQuery.chat_instance,
data=TestCallbackQuery.data,
Expand All @@ -38,7 +38,7 @@ def callback_query(bot, request):


class TestCallbackQuery(object):
id = 'id'
id_ = 'id'
from_user = User(1, 'test_user', False)
chat_instance = 'chat_instance'
message = Message(3, User(5, 'bot', False), None, Chat(4, 'private'))
Expand All @@ -47,7 +47,7 @@ class TestCallbackQuery(object):
game_short_name = 'the_game'

def test_de_json(self, bot):
json_dict = {'id': self.id,
json_dict = {'id': self.id_,
'from': self.from_user.to_dict(),
'chat_instance': self.chat_instance,
'message': self.message.to_dict(),
Expand All @@ -57,7 +57,7 @@ def test_de_json(self, bot):
'default_quote': True}
callback_query = CallbackQuery.de_json(json_dict, bot)

assert callback_query.id == self.id
assert callback_query.id == self.id_
assert callback_query.from_user == self.from_user
assert callback_query.chat_instance == self.chat_instance
assert callback_query.message == self.message
Expand Down Expand Up @@ -92,8 +92,8 @@ def test_edit_message_text(self, monkeypatch, callback_query):
def test(*args, **kwargs):
text = args[0] == 'test'
try:
id = kwargs['inline_message_id'] == callback_query.inline_message_id
return id and text
id_ = kwargs['inline_message_id'] == callback_query.inline_message_id
return id_ and text
except KeyError:
chat_id = kwargs['chat_id'] == callback_query.message.chat_id
message_id = kwargs['message_id'] == callback_query.message.message_id
Expand All @@ -107,12 +107,12 @@ def test_edit_message_caption(self, monkeypatch, callback_query):
def test(*args, **kwargs):
caption = kwargs['caption'] == 'new caption'
try:
id = kwargs['inline_message_id'] == callback_query.inline_message_id
return id and caption
id_ = kwargs['inline_message_id'] == callback_query.inline_message_id
return id_ and caption
except KeyError:
id = kwargs['chat_id'] == callback_query.message.chat_id
id_ = kwargs['chat_id'] == callback_query.message.chat_id
message = kwargs['message_id'] == callback_query.message.message_id
return id and message and caption
return id_ and message and caption

monkeypatch.setattr(callback_query.bot, 'edit_message_caption', test)
assert callback_query.edit_message_caption(caption='new caption')
Expand All @@ -122,23 +122,23 @@ def test_edit_message_reply_markup(self, monkeypatch, callback_query):
def test(*args, **kwargs):
reply_markup = kwargs['reply_markup'] == [['1', '2']]
try:
id = kwargs['inline_message_id'] == callback_query.inline_message_id
return id and reply_markup
id_ = kwargs['inline_message_id'] == callback_query.inline_message_id
return id_ and reply_markup
except KeyError:
id = kwargs['chat_id'] == callback_query.message.chat_id
id_ = kwargs['chat_id'] == callback_query.message.chat_id
message = kwargs['message_id'] == callback_query.message.message_id
return id and message and reply_markup
return id_ and message and reply_markup

monkeypatch.setattr(callback_query.bot, 'edit_message_reply_markup', test)
assert callback_query.edit_message_reply_markup(reply_markup=[['1', '2']])
assert callback_query.edit_message_reply_markup([['1', '2']])

def test_equality(self):
a = CallbackQuery(self.id, self.from_user, 'chat')
b = CallbackQuery(self.id, self.from_user, 'chat')
c = CallbackQuery(self.id, None, '')
a = CallbackQuery(self.id_, self.from_user, 'chat')
b = CallbackQuery(self.id_, self.from_user, 'chat')
c = CallbackQuery(self.id_, None, '')
d = CallbackQuery('', None, 'chat')
e = Audio(self.id, 1)
e = Audio(self.id_, 1)

assert a == b
assert hash(a) == hash(b)
Expand Down
32 changes: 16 additions & 16 deletions tests/test_chat.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,17 @@

@pytest.fixture(scope='class')
def chat(bot):
return Chat(TestChat.id, TestChat.title, TestChat.type, username=TestChat.username,
return Chat(TestChat.id_, TestChat.title, TestChat.type_, username=TestChat.username,
all_members_are_administrators=TestChat.all_members_are_administrators,
bot=bot, sticker_set_name=TestChat.sticker_set_name,
can_set_sticker_set=TestChat.can_set_sticker_set,
permissions=TestChat.permissions)


class TestChat(object):
id = -28767330
id_ = -28767330
title = 'ToledosPalaceBot - Group'
type = 'group'
type_ = 'group'
username = 'username'
all_members_are_administrators = False
sticker_set_name = 'stickers'
Expand All @@ -48,9 +48,9 @@ class TestChat(object):

def test_de_json(self, bot):
json_dict = {
'id': self.id,
'id': self.id_,
'title': self.title,
'type': self.type,
'type': self.type_,
'username': self.username,
'all_members_are_administrators': self.all_members_are_administrators,
'sticker_set_name': self.sticker_set_name,
Expand All @@ -59,9 +59,9 @@ def test_de_json(self, bot):
}
chat = Chat.de_json(json_dict, bot)

assert chat.id == self.id
assert chat.id == self.id_
assert chat.title == self.title
assert chat.type == self.type
assert chat.type == self.type_
assert chat.username == self.username
assert chat.all_members_are_administrators == self.all_members_are_administrators
assert chat.sticker_set_name == self.sticker_set_name
Expand All @@ -70,8 +70,8 @@ def test_de_json(self, bot):

def test_de_json_default_quote(self, bot):
json_dict = {
'id': self.id,
'type': self.type,
'id': self.id_,
'type': self.type_,
'pinned_message': Message(
message_id=123,
from_user=None,
Expand Down Expand Up @@ -102,9 +102,9 @@ def test_link(self, chat):

def test_send_action(self, monkeypatch, chat):
def test(*args, **kwargs):
id = args[0] == chat.id
id_ = args[0] == chat.id
action = kwargs['action'] == ChatAction.TYPING
return id and action
return id_ and action

monkeypatch.setattr(chat.bot, 'send_chat_action', test)
assert chat.send_action(action=ChatAction.TYPING)
Expand Down Expand Up @@ -238,11 +238,11 @@ def test(*args, **kwargs):
assert chat.send_poll('test_poll')

def test_equality(self):
a = Chat(self.id, self.title, self.type)
b = Chat(self.id, self.title, self.type)
c = Chat(self.id, '', '')
d = Chat(0, self.title, self.type)
e = User(self.id, '', False)
a = Chat(self.id_, self.title, self.type_)
b = Chat(self.id_, self.title, self.type_)
c = Chat(self.id_, '', '')
d = Chat(0, self.title, self.type_)
e = User(self.id_, '', False)

assert a == b
assert hash(a) == hash(b)
Expand Down
10 changes: 5 additions & 5 deletions tests/test_encryptedpassportelement.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

@pytest.fixture(scope='class')
def encrypted_passport_element():
return EncryptedPassportElement(TestEncryptedPassportElement.type,
return EncryptedPassportElement(TestEncryptedPassportElement.type_,
data=TestEncryptedPassportElement.data,
phone_number=TestEncryptedPassportElement.phone_number,
email=TestEncryptedPassportElement.email,
Expand All @@ -35,7 +35,7 @@ def encrypted_passport_element():


class TestEncryptedPassportElement(object):
type = 'type'
type_ = 'type'
data = 'data'
phone_number = 'phone_number'
email = 'email'
Expand All @@ -45,7 +45,7 @@ class TestEncryptedPassportElement(object):
selfie = PassportFile('file_id', 50, 0)

def test_expected_values(self, encrypted_passport_element):
assert encrypted_passport_element.type == self.type
assert encrypted_passport_element.type == self.type_
assert encrypted_passport_element.data == self.data
assert encrypted_passport_element.phone_number == self.phone_number
assert encrypted_passport_element.email == self.email
Expand Down Expand Up @@ -75,8 +75,8 @@ def test_to_dict(self, encrypted_passport_element):
== encrypted_passport_element.selfie.to_dict())

def test_equality(self):
a = EncryptedPassportElement(self.type, data=self.data)
b = EncryptedPassportElement(self.type, data=self.data)
a = EncryptedPassportElement(self.type_, data=self.data)
b = EncryptedPassportElement(self.type_, data=self.data)
c = EncryptedPassportElement(self.data, '')
d = PassportElementError('source', 'type', 'message')

Expand Down
16 changes: 8 additions & 8 deletions tests/test_inlinequery.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,28 +24,28 @@

@pytest.fixture(scope='class')
def inline_query(bot):
return InlineQuery(TestInlineQuery.id, TestInlineQuery.from_user, TestInlineQuery.query,
return InlineQuery(TestInlineQuery.id_, TestInlineQuery.from_user, TestInlineQuery.query,
TestInlineQuery.offset, location=TestInlineQuery.location, bot=bot)


class TestInlineQuery(object):
id = 1234
id_ = 1234
from_user = User(1, 'First name', False)
query = 'query text'
offset = 'offset'
location = Location(8.8, 53.1)

def test_de_json(self, bot):
json_dict = {
'id': self.id,
'id': self.id_,
'from': self.from_user.to_dict(),
'query': self.query,
'offset': self.offset,
'location': self.location.to_dict()
}
inline_query_json = InlineQuery.de_json(json_dict, bot)

assert inline_query_json.id == self.id
assert inline_query_json.id == self.id_
assert inline_query_json.from_user == self.from_user
assert inline_query_json.location == self.location
assert inline_query_json.query == self.query
Expand All @@ -69,11 +69,11 @@ def test(*args, **kwargs):
assert inline_query.answer()

def test_equality(self):
a = InlineQuery(self.id, User(1, '', False), '', '')
b = InlineQuery(self.id, User(1, '', False), '', '')
c = InlineQuery(self.id, User(0, '', False), '', '')
a = InlineQuery(self.id_, User(1, '', False), '', '')
b = InlineQuery(self.id_, User(1, '', False), '', '')
c = InlineQuery(self.id_, User(0, '', False), '', '')
d = InlineQuery(0, User(1, '', False), '', '')
e = Update(self.id)
e = Update(self.id_)

assert a == b
assert hash(a) == hash(b)
Expand Down
18 changes: 9 additions & 9 deletions tests/test_inlinequeryresultarticle.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
@pytest.fixture(scope='class')
def inline_query_result_article():
return InlineQueryResultArticle(
TestInlineQueryResultArticle.id,
TestInlineQueryResultArticle.id_,
TestInlineQueryResultArticle.title,
input_message_content=TestInlineQueryResultArticle.input_message_content,
reply_markup=TestInlineQueryResultArticle.reply_markup,
Expand All @@ -39,8 +39,8 @@ def inline_query_result_article():


class TestInlineQueryResultArticle(object):
id = 'id'
type = 'article'
id_ = 'id'
type_ = 'article'
title = 'title'
input_message_content = InputTextMessageContent('input_message_content')
reply_markup = InlineKeyboardMarkup([[InlineKeyboardButton('reply_markup')]])
Expand All @@ -52,8 +52,8 @@ class TestInlineQueryResultArticle(object):
thumb_width = 15

def test_expected_values(self, inline_query_result_article):
assert inline_query_result_article.type == self.type
assert inline_query_result_article.id == self.id
assert inline_query_result_article.type == self.type_
assert inline_query_result_article.id == self.id_
assert inline_query_result_article.title == self.title
assert (inline_query_result_article.input_message_content.to_dict()
== self.input_message_content.to_dict())
Expand Down Expand Up @@ -88,11 +88,11 @@ def test_to_dict(self, inline_query_result_article):
== inline_query_result_article.thumb_width)

def test_equality(self):
a = InlineQueryResultArticle(self.id, self.title, self.input_message_content)
b = InlineQueryResultArticle(self.id, self.title, self.input_message_content)
c = InlineQueryResultArticle(self.id, '', self.input_message_content)
a = InlineQueryResultArticle(self.id_, self.title, self.input_message_content)
b = InlineQueryResultArticle(self.id_, self.title, self.input_message_content)
c = InlineQueryResultArticle(self.id_, '', self.input_message_content)
d = InlineQueryResultArticle('', self.title, self.input_message_content)
e = InlineQueryResultAudio(self.id, '', '')
e = InlineQueryResultAudio(self.id_, '', '')

assert a == b
assert hash(a) == hash(b)
Expand Down
18 changes: 9 additions & 9 deletions tests/test_inlinequeryresultaudio.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
@pytest.fixture(scope='class')
def inline_query_result_audio():
return InlineQueryResultAudio(
TestInlineQueryResultAudio.id,
TestInlineQueryResultAudio.id_,
TestInlineQueryResultAudio.audio_url,
TestInlineQueryResultAudio.title,
performer=TestInlineQueryResultAudio.performer,
Expand All @@ -38,8 +38,8 @@ def inline_query_result_audio():


class TestInlineQueryResultAudio(object):
id = 'id'
type = 'audio'
id_ = 'id'
type_ = 'audio'
audio_url = 'audio url'
title = 'title'
performer = 'performer'
Expand All @@ -50,8 +50,8 @@ class TestInlineQueryResultAudio(object):
reply_markup = InlineKeyboardMarkup([[InlineKeyboardButton('reply_markup')]])

def test_expected_values(self, inline_query_result_audio):
assert inline_query_result_audio.type == self.type
assert inline_query_result_audio.id == self.id
assert inline_query_result_audio.type == self.type_
assert inline_query_result_audio.id == self.id_
assert inline_query_result_audio.audio_url == self.audio_url
assert inline_query_result_audio.title == self.title
assert inline_query_result_audio.performer == self.performer
Expand Down Expand Up @@ -81,11 +81,11 @@ def test_to_dict(self, inline_query_result_audio):
== inline_query_result_audio.reply_markup.to_dict())

def test_equality(self):
a = InlineQueryResultAudio(self.id, self.audio_url, self.title)
b = InlineQueryResultAudio(self.id, self.title, self.title)
c = InlineQueryResultAudio(self.id, '', self.title)
a = InlineQueryResultAudio(self.id_, self.audio_url, self.title)
b = InlineQueryResultAudio(self.id_, self.title, self.title)
c = InlineQueryResultAudio(self.id_, '', self.title)
d = InlineQueryResultAudio('', self.audio_url, self.title)
e = InlineQueryResultVoice(self.id, '', '')
e = InlineQueryResultVoice(self.id_, '', '')

assert a == b
assert hash(a) == hash(b)
Expand Down
Loading