Sourcery refactored main branch - #4
Conversation
4adb6bc to
b791b91
Compare
| # Here I'm printing the file and line number, | ||
| # but you can examine the frame, locals, etc too. | ||
| print("%s @ %s" % (filename, lineno)) | ||
| print(f"{filename} @ {lineno}") |
There was a problem hiding this comment.
Function trace refactored with the following changes:
- Replace interpolated string formatting with f-string (
replace-interpolation-with-fstring)
| x = open("mybotr.po", "a") | ||
| with open('mybot.po', encoding='UTF-8') as f: | ||
| idblock="" | ||
| idblock2="" | ||
| lines = f.readlines() | ||
| for row in lines: | ||
| if row[0] == '"': | ||
| idblock = idblock + row | ||
| xr2 = deepl.translate(source_language="RU", target_language="EN", text=row) | ||
| idblock2 = idblock2 + xr2 | ||
| print(idblock) | ||
| print(idblock2) | ||
| print("1") | ||
| if 'msgid ' in row: | ||
| print("2") | ||
| print("2-1") | ||
| if 'msgid ""' in row: | ||
| idblock= idblock + 'msgid ""' + "\n" | ||
| idblock2= idblock2 + 'msgstr ""' + "\n" | ||
| #x.write('msgid ""\n') | ||
| else: | ||
| idblock= idblock + row + "\n" | ||
| xb2 = deepl.translate(source_language="RU", target_language="EN", text=row[7:]) | ||
| idblock2= idblock2 + 'msgstr ' + xb2 | ||
| with open("mybotr.po", "a") as x: | ||
| with open('mybot.po', encoding='UTF-8') as f: | ||
| idblock="" | ||
| idblock2="" | ||
| lines = f.readlines() | ||
| for row in lines: | ||
| if row[0] == '"': | ||
| idblock = idblock + row | ||
| xr2 = deepl.translate(source_language="RU", target_language="EN", text=row) | ||
| idblock2 = idblock2 + xr2 | ||
| print(idblock) | ||
| print(idblock2) | ||
| print("1") | ||
| if 'msgid ' in row: | ||
| print("2") | ||
| print("2-1") | ||
| if 'msgid ""' in row: | ||
| idblock = f'{idblock}msgid ""' + "\n" | ||
| idblock2 = f'{idblock2}msgstr ""' + "\n" | ||
| else: | ||
| idblock= idblock + row + "\n" | ||
| xb2 = deepl.translate(source_language="RU", target_language="EN", text=row[7:]) | ||
| idblock2 = f'{idblock2}msgstr {xb2}' | ||
| continue | ||
| print(row[7:]) | ||
| #x.write('msgstr ' + row[6:]) | ||
| elif 'msgstr' in row: | ||
| print("3") | ||
| x.write(idblock) | ||
| x.write(idblock2) | ||
| idblock = "" | ||
| idblock2 = "" | ||
| continue | ||
| print(row[7:]) | ||
| #x.write('msgstr ' + row[6:]) | ||
| elif 'msgstr' in row: | ||
| print("3") | ||
| x.write(idblock) | ||
| x.write(idblock2) | ||
| idblock = "" | ||
| idblock2 = "" | ||
| continue | ||
| elif row[0] == "\n": | ||
| print("4") | ||
| x.write('\n') | ||
| #idblock= idblock + row | ||
| #idblock2= idblock2 + row | ||
| else: | ||
| xrow = deepl.translate(source_language="RU", target_language="EN", text=row) | ||
| x.write(xrow) | ||
| x.close() | ||
| elif row[0] == "\n": | ||
| print("4") | ||
| x.write('\n') | ||
| #idblock= idblock + row | ||
| #idblock2= idblock2 + row | ||
| else: | ||
| xrow = deepl.translate(source_language="RU", target_language="EN", text=row) | ||
| x.write(xrow) |
There was a problem hiding this comment.
Lines 5-47 refactored with the following changes:
- Use
withwhen opening file to ensure closure (ensure-file-closed) - Use f-string instead of string concatenation [×4] (
use-fstring-for-concatenation)
This removes the following comments ( why? ):
#x.write('msgid ""\n')
| sec %= 60 | ||
|
|
||
| print(f"{str(cur_time.hour)}:{str(cur_time.minute)}") | ||
| print(f"{cur_time.hour}:{cur_time.minute}") |
There was a problem hiding this comment.
Lines 309-309 refactored with the following changes:
- Simplify conditional into switch-like form [×2] (
switch) - Remove unnecessary calls to
str()from formatted values in f-strings [×2] (remove-str-from-fstring)
| if dialog.chat.type == ChatType.GROUP or dialog.chat.type == ChatType.SUPERGROUP: | ||
| if dialog.chat.type in [ChatType.GROUP, ChatType.SUPERGROUP]: | ||
| for v in ids: | ||
| s = v | ||
| del ids[:1] | ||
|
|
There was a problem hiding this comment.
Function inviter refactored with the following changes:
- Replace multiple comparisons of same variable with
inoperator (merge-comparisons)
| mode = "tohour" | ||
| ct = 0 | ||
| shortlen = 450 | ||
| shortmestext = message.html_text[0:449] | ||
| shortmestext = message.html_text[:449] | ||
|
|
||
| if user_role in ["Admin", "ShopAdmin"]: | ||
| print("P10P20R") | ||
| mode = "tohour" |
There was a problem hiding this comment.
Function functions_ad_get refactored with the following changes:
- Move assignments closer to their usage (
move-assign) - Replace a[0:x] with a[:x] and a[x:len(a)] with a[x:] (
remove-redundant-slice-index)
| #async with state.proxy() as data: | ||
| # position_id = data['here_position_id'] | ||
| # print(position_id) | ||
| lang = "ru" | ||
| #await state.set_state("here_position_time_selection") | ||
| if selected: | ||
| #async with state.proxy() as data: | ||
| # position_id = data['here_position_id'] | ||
| # print(position_id) | ||
| lang = "ru" |
There was a problem hiding this comment.
Function process_simple_calendar refactored with the following changes:
- Move assignments closer to their usage (
move-assign)
| user_id = call.from_user.id | ||
| lang = "ru" | ||
| if r.selected: | ||
| user_id = call.from_user.id | ||
| lang = "ru" |
There was a problem hiding this comment.
Function process_hour_timepicker refactored with the following changes:
- Move assignments closer to their usage (
move-assign)
| text=f"Пожалуйста, выберите дату для постинга позиции:", | ||
| reply_markup=await SimpleCalendar().start_calendar() | ||
| text="Пожалуйста, выберите дату для постинга позиции:", | ||
| reply_markup=await SimpleCalendar().start_calendar(), |
There was a problem hiding this comment.
Function product_position_planning_approve refactored with the following changes:
- Replace f-string with no interpolated values with string (
remove-redundant-fstring)
| user_id = call.from_user.id | ||
|
|
||
| if decision == "yes": | ||
| await update_positionx(position_id, position_state="Broadcast") | ||
|
|
||
| user_id = call.from_user.id | ||
|
|
There was a problem hiding this comment.
Function product_position_planning_approve refactored with the following changes:
- Move assignments closer to their usage (
move-assign)
| user_requests = get_requestx(requester=user_id) | ||
| #print(user_requests) | ||
|
|
||
| if user_requests: | ||
| if user_requests := get_requestx(requester=user_id): | ||
| await message.answer("У Вас уже есть запросы продавца |||| Если админ Вам не подтвердил запрос, напишите: @raclear") | ||
| #for request in user_requests: | ||
| #print(request) | ||
| await message.answer(open_profile_search_req(user_id, lang), reply_markup=menu_frep(user_id, lang)) | ||
| await state.set_state("here_seller_request_direction") | ||
| await message.answer(_("<b>📁 Введите тип товара, который Вы будете продавать:</b>", locale=lang)) | ||
| else: | ||
| await state.set_state("here_seller_request_direction") | ||
| await message.answer(_("<b>📁 Введите тип товара, который Вы будете продавать:</b>", locale=lang)) | ||
| await state.set_state("here_seller_request_direction") | ||
| await message.answer(_("<b>📁 Введите тип товара, который Вы будете продавать:</b>", locale=lang)) |
There was a problem hiding this comment.
Function user_seller_request refactored with the following changes:
- Use named expression to simplify assignment and conditional (
use-named-expression) - Hoist repeated code outside conditional statement [×2] (
hoist-statement-from-if)
This removes the following comments ( why? ):
#print(user_requests)
| action = "edit" | ||
| if user_role in ["Admin", "ShopAdmin"]: | ||
| await state.finish() | ||
| action = "edit" |
There was a problem hiding this comment.
Function product_position_edit refactored with the following changes:
- Move assignments closer to their usage (
move-assign)
| if user_role == "Admin" or user_role == "ShopAdmin": #user_id in get_admins(): # | ||
| if user_role in ["Admin", "ShopAdmin"]: #user_id in get_admins(): # |
There was a problem hiding this comment.
Function payment_systems refactored with the following changes:
- Replace multiple comparisons of same variable with
inoperator (merge-comparisons)
| if user_role == "Admin" or user_role == "ShopAdmin": | ||
| if user_role in ["Admin", "ShopAdmin"]: |
There was a problem hiding this comment.
Function product_position_create_select_category refactored with the following changes:
- Replace multiple comparisons of same variable with
inoperator (merge-comparisons)
| #else: city_id = int(call.data.split(":")[3]) | ||
| print(category_id, city_id, get_category) | ||
|
|
||
| source = "people" |
There was a problem hiding this comment.
Function product_position_open_select_category refactored with the following changes:
- Move assignments closer to their usage (
move-assign)
| action = "edit" | ||
| source = "commercial" |
There was a problem hiding this comment.
Function product_position_create_select_category refactored with the following changes:
- Move assignments closer to their usage (
move-assign)
| priceusdt = response['price'] | ||
| return priceusdt | ||
| return response['price'] |
There was a problem hiding this comment.
Function GetUSDTPrice refactored with the following changes:
- Inline variable that is immediately returned (
inline-immediately-returned-variable)
| btc_price = response['price'] | ||
| return btc_price | ||
| return response['price'] |
There was a problem hiding this comment.
Function GetBtcPrice refactored with the following changes:
- Inline variable that is immediately returned (
inline-immediately-returned-variable)
| tokens = response.json() | ||
|
|
||
| return tokens | ||
| return response.json() |
There was a problem hiding this comment.
Function getTokens refactored with the following changes:
- Inline variable that is immediately returned (
inline-immediately-returned-variable)
| tron_address = get_tron_address(call.from_user.id) | ||
| trx_addr_txt = "" | ||
| if tron_address: trx_addr_txt = f"<b>Ваш текущий Tron TRC20 адрес</b>: {tron_address['tron_address']}\n" | ||
| if tron_address := get_tron_address(call.from_user.id): | ||
| trx_addr_txt = f"<b>Ваш текущий Tron TRC20 адрес</b>: {tron_address['tron_address']}\n" | ||
| else: | ||
| trx_addr_txt = "" |
There was a problem hiding this comment.
Function change_trc20 refactored with the following changes:
- Move setting of default value for variable into
elsebranch (introduce-default-else) - Use named expression to simplify assignment and conditional (
use-named-expression)
| btcb_address = get_crypto_address(call.from_user.id, "BTCB") | ||
| btcb_addr_txt = "" | ||
| if btcb_address: btcb_addr_txt = f"<b>Ваш текущий BTC BEP20 адрес</b>: {btcb_address['tron_address']}\n" | ||
| if btcb_address := get_crypto_address(call.from_user.id, "BTCB"): | ||
| btcb_addr_txt = f"<b>Ваш текущий BTC BEP20 адрес</b>: {btcb_address['tron_address']}\n" | ||
| else: | ||
| btcb_addr_txt = "" |
There was a problem hiding this comment.
Function change_trc20 refactored with the following changes:
- Move setting of default value for variable into
elsebranch (introduce-default-else) - Use named expression to simplify assignment and conditional (
use-named-expression)
| ).bill_pay(pay_amount, get_way) | ||
|
|
||
| if get_way == "Tron" or get_way == "BTCB": | ||
| if get_way in ["Tron", "BTCB"]: |
There was a problem hiding this comment.
Function refill_get refactored with the following changes:
- Replace multiple comparisons of same variable with
inoperator [×5] (merge-comparisons) - Split conditional into multiple branches [×5] (
split-or-ifs) - Merge duplicate blocks in conditional [×5] (
merge-duplicate-blocks) - Move assignments closer to their usage (
move-assign) - Remove redundant conditional [×5] (
remove-redundant-if)
| await call.answer(f"♻ Подождите, платёж проверяется...") | ||
| await call.answer("♻ Подождите, платёж проверяется...") |
There was a problem hiding this comment.
Function refill_check_tron refactored with the following changes:
- Replace f-string with no interpolated values with string [×2] (
remove-redundant-fstring)
| await call.answer(f"♻ Подождите, платёж проверяется...") | ||
| await call.answer("♻ Подождите, платёж проверяется...") |
There was a problem hiding this comment.
Function refill_check_tron refactored with the following changes:
- Replace f-string with no interpolated values with string [×2] (
remove-redundant-fstring)
| await message.answer(f"<b>♻ Был введен пустой адрес</b>", reply_markup=back_to_profile_finl('ru')) | ||
| await message.answer( | ||
| "<b>♻ Был введен пустой адрес</b>", | ||
| reply_markup=back_to_profile_finl('ru'), | ||
| ) |
There was a problem hiding this comment.
Function enter_tron_address refactored with the following changes:
- Replace f-string with no interpolated values with string (
remove-redundant-fstring) - Hoist repeated code outside conditional statement (
hoist-statement-from-if)
| await message.answer(f"<b>♻ Успешно сохранили Ваш BEP-20 адрес в профиле.</b>", reply_markup=back_to_profile_finl('ru')) | ||
| await message.answer( | ||
| "<b>♻ Успешно сохранили Ваш BEP-20 адрес в профиле.</b>", | ||
| reply_markup=back_to_profile_finl('ru'), | ||
| ) |
There was a problem hiding this comment.
Function enter_tron_address refactored with the following changes:
- Replace f-string with no interpolated values with string (
remove-redundant-fstring)
| if lang == "ru": | ||
| dbtn = "❌ Да, удалить" | ||
| cbtn = "✅ Нет, отменить" | ||
|
|
||
| if lang == "en": | ||
| dbtn = "❌ Yes, Delete Please" | ||
| cbtn = "✅ No, Cancel Please" | ||
|
|
||
| elif lang == "ru": | ||
| dbtn = "❌ Да, удалить" | ||
| cbtn = "✅ Нет, отменить" |
There was a problem hiding this comment.
Function category_edit_delete_finl refactored with the following changes:
- Simplify conditional into switch-like form (
switch)
| if lang == "ru": | ||
| yesbtn = "❌ Да, удалить" | ||
| nobtn = "✅ Нет, отменить" | ||
| if lang == "en": | ||
| if lang in ["ru", "en"]: | ||
| yesbtn = "❌ Да, удалить" | ||
| nobtn = "✅ Нет, отменить" | ||
|
|
There was a problem hiding this comment.
Function shop_edit_delete_finl2 refactored with the following changes:
- Simplify conditional into switch-like form (
switch)
| if lang == "ru": | ||
| chnbtn = "🏷 Изм. название" | ||
| chpbtn = "💰 Изм. цену" | ||
| chdbtn = "📜 Изм. описание" | ||
| chphbtn = "📸 Изм. фото" | ||
| chrbtn = "📜 Изменить остаток" | ||
| chlbtn = "📸 <---<ВП>-->" | ||
| chcbtn = "🏙 Изм. город" | ||
| chsbtn = "🏙 Изм. магазин" | ||
| chclbtn = "🗑 Очистить" | ||
| agbtn = "🎁 Добавить товары" | ||
| prsbtn = "📥 Товары" | ||
| delbtn = "❌ Удалить" | ||
| backbtn = "⬅ Вернуться ↩" |
There was a problem hiding this comment.
Function position_edit_open_finl refactored with the following changes:
- Simplify conditional into switch-like form (
switch)
| if lang == "ru": | ||
| dbtn = "❌ Да, удалить" | ||
| cbtn = "✅ Нет, отменить" | ||
| if lang == "en": | ||
| dbtn = "❌ Yes, Delete" | ||
| cbtn = "✅ No, Cancel" | ||
|
|
||
| elif lang == "ru": | ||
| dbtn = "❌ Да, удалить" | ||
| cbtn = "✅ Нет, отменить" |
There was a problem hiding this comment.
Function position_edit_delete_finl refactored with the following changes:
- Simplify conditional into switch-like form (
switch)
| if lang == "ru": | ||
| clbtn = "❌ Да, очистить" | ||
| ccbtn = "✅ Нет, отменить" | ||
| if lang == "en": | ||
| clbtn = "❌ Yes, Clear" | ||
| ccbtn = "✅ No, Cancel" | ||
|
|
||
| elif lang == "ru": | ||
| clbtn = "❌ Да, очистить" | ||
| ccbtn = "✅ Нет, отменить" |
There was a problem hiding this comment.
Function position_edit_clear_finl refactored with the following changes:
- Simplify conditional into switch-like form (
switch)
b791b91 to
eb1dcb4
Compare
Branch
mainrefactored by Sourcery.If you're happy with these changes, merge this Pull Request using the Squash and merge strategy.
See our documentation here.
Run Sourcery locally
Reduce the feedback loop during development by using the Sourcery editor plugin:
Review changes via command line
To manually merge these changes, make sure you're on the
mainbranch, then run:Help us improve this pull request!