Skip to content

Commit c18dd8a

Browse files
committed
fix: flake8 lint rules
Remove unnecessary global declarations across multiple test files. This change improves code quality by eliminating redundant global statements for variables that are already accessible in their respective scopes. Add proper type annotation for fees_from_status in test_closing.py and import the required typing modules. These changes maintain the same functionality while making the code cleaner and more compliant with Python best practices.
1 parent cdd5065 commit c18dd8a

File tree

4 files changed

+3
-14
lines changed

4 files changed

+3
-14
lines changed

contrib/pyln-testing/pyln/testing/fixtures.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,6 @@ def directory(request, test_base_dir, test_name):
7474
This makes a unique test-directory even if a test is rerun multiple times.
7575
7676
"""
77-
global __attempts
7877
# Auto set value if it isn't in the dict yet
7978
__attempts[test_name] = __attempts.get(test_name, 0) + 1
8079
directory = os.path.join(test_base_dir, "{}_{}".format(test_name, __attempts[test_name]))

tests/autogenerate-rpc-examples.py

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -366,7 +366,6 @@ def update_examples_in_schema_files():
366366
updated_examples = {}
367367
for method, method_examples in EXAMPLES_JSON.items():
368368
try:
369-
global CWD
370369
file_path = os.path.join(CWD, 'doc', 'schemas', f'{method}.json') if method != 'sql' else os.path.join(CWD, 'doc', 'schemas', f'{method}-template.json')
371370
logger.info(f'Updating examples for {method} in file {file_path}')
372371
with open(file_path, 'r+', encoding='utf-8') as file:
@@ -441,7 +440,6 @@ def setup_test_nodes(node_factory, bitcoind):
441440
l6.info['id']: 0265b6ab5ec860cd257865d61ef0bbf5b3339c36cbda8b26b74e7f1dca490b6518
442441
"""
443442
try:
444-
global FUND_WALLET_AMOUNT_SAT, FUND_CHANNEL_AMOUNT_SAT
445443
options = [
446444
{
447445
'experimental-dual-fund': None,
@@ -537,7 +535,6 @@ def generate_transactions_examples(l1, l2, l3, l4, l5, c25, bitcoind):
537535
"""Generate examples for various transactions and forwards"""
538536
try:
539537
logger.info('Simple Transactions Start...')
540-
global FUND_CHANNEL_AMOUNT_SAT
541538
# Simple Transactions by creating invoices, paying invoices, keysends
542539
inv_l31 = update_example(node=l3, method='invoice', params={'amount_msat': 10**4, 'label': 'lbl_l31', 'description': 'Invoice description l31'})
543540
route_l1_l3 = update_example(node=l1, method='getroute', params={'id': l3.info['id'], 'amount_msat': 10**4, 'riskfactor': 1})['route']
@@ -1157,7 +1154,6 @@ def generate_utils_examples(l1, l2, l3, l4, l5, l6, c23_2, c34_2, inv_l11, inv_l
11571154
"""Generates other utilities examples"""
11581155
try:
11591156
logger.info('General Utils Start...')
1160-
global CWD, FUND_CHANNEL_AMOUNT_SAT
11611157
update_example(node=l2, method='batching', params={'enable': True})
11621158
update_example(node=l2, method='ping', params={'id': l1.info['id'], 'len': 128, 'pongbytes': 128})
11631159
update_example(node=l2, method='ping', params={'id': l3.info['id'], 'len': 1000, 'pongbytes': 65535})
@@ -1303,7 +1299,6 @@ def generate_splice_examples(node_factory, bitcoind):
13031299
"""Generates splice related examples"""
13041300
try:
13051301
logger.info('Splice Start...')
1306-
global FUND_WALLET_AMOUNT_SAT, FUND_CHANNEL_AMOUNT_SAT
13071302
# Basic setup for l7->l8
13081303
options = [
13091304
{
@@ -1376,7 +1371,6 @@ def generate_channels_examples(node_factory, bitcoind, l1, l3, l4, l5):
13761371
"""Generates fundchannel and openchannel related examples"""
13771372
try:
13781373
logger.info('Channels Start...')
1379-
global FUND_WALLET_AMOUNT_SAT, FUND_CHANNEL_AMOUNT_SAT
13801374
# Basic setup for l9->l10 for fundchannel examples
13811375
options = [
13821376
{
@@ -1684,7 +1678,6 @@ def generate_autoclean_delete_examples(l1, l2, l3, l4, l5, c12, c23):
16841678
"""Records autoclean and delete examples"""
16851679
try:
16861680
logger.info('Auto-clean and Delete Start...')
1687-
global FUND_CHANNEL_AMOUNT_SAT
16881681
l2.rpc.close(l5.info['id'])
16891682
dfc_res1 = update_example(node=l2, method='dev-forget-channel', params={'id': l5.info['id']}, description=[f'Forget a channel by peer pubkey when only one channel exists with the peer:'])
16901683

@@ -2034,7 +2027,6 @@ def generate_list_examples(l1, l2, l3, c12, c23_2, inv_l31, inv_l32, offer_l23,
20342027

20352028
@pytest.fixture(autouse=True)
20362029
def setup_logging():
2037-
global logger
20382030
logger.setLevel(logging.DEBUG)
20392031
formatter = logging.Formatter("%(asctime)s - %(levelname)s - %(message)s", "%H:%M:%S")
20402032
stream_handler = logging.StreamHandler()
@@ -2054,7 +2046,6 @@ def test_generate_examples(node_factory, bitcoind, executor):
20542046
def list_all_examples():
20552047
"""list all methods used in 'update_example' calls to ensure that all methods are covered"""
20562048
try:
2057-
global REGENERATING_RPCS
20582049
methods = []
20592050
file_path = os.path.abspath(__file__)
20602051

@@ -2076,7 +2067,6 @@ def list_all_examples():
20762067
def list_missing_examples():
20772068
"""Checks for missing example & log an error if missing."""
20782069
try:
2079-
global ALL_RPC_EXAMPLES
20802070
missing_examples = ''
20812071
for file_name in os.listdir('doc/schemas'):
20822072
if not file_name.endswith('.json'):

tests/plugins/block_added.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010

1111
@plugin.subscribe("block_added")
1212
def notify_block_added(plugin, block_added, **kwargs):
13-
global blocks_catched
1413
blocks_catched.append(block_added["height"])
1514

1615

tests/test_closing.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
first_scid, check_feerate
1212
)
1313

14+
from typing import List, Optional
15+
1416
import bitcoin
1517
import os
1618
import queue
@@ -392,10 +394,9 @@ def feerate_for(target, minimum=0, maximum=10000000):
392394
status_agreed_regex = re.compile("agreed on a closing fee of ([0-9]+) satoshi")
393395

394396
# [fee_from_opener_status, fee_from_peer_status]
395-
fees_from_status = [None, None]
397+
fees_from_status: List[Optional[int], Optional[int]] = [None, None]
396398

397399
def get_fee_from_status(node, peer_id, i):
398-
nonlocal fees_from_status
399400
channel = only_one(node.rpc.listpeerchannels(peer_id)['channels'])
400401
status = channel['status'][0]
401402

0 commit comments

Comments
 (0)