Skip to content

Conversation

@DashCoreAutoGuix
Copy link
Owner

@DashCoreAutoGuix DashCoreAutoGuix commented Sep 30, 2025

Summary

Backport of Bitcoin Core PR bitcoin#27279 (commit 6a16732).

This PR adds a new warnings field (as a JSON array of strings) to wallet RPCs createwallet, loadwallet, unloadwallet, and restorewallet, while deprecating the existing warning string field. This improves handling of multiple warning messages and provides consistency with other wallet RPCs.

Key Changes:

  • Added PushWarnings() helper functions in src/rpc/util.cpp and src/rpc/util.h to standardize warning output
  • Updated wallet RPCs to include both warning (deprecated) and warnings (new array format) fields
  • Added -deprecatedrpc=walletwarningfield flag to control whether the deprecated warning field is returned
  • Updated functional tests to verify both old and new warning formats

Dash-Specific Adaptations:

  • Changed "bitcoind" references to "dashd" in help text
  • Removed backport of wallet_backwards_compatibility.py test which doesn't exist in Dash
  • Conflicts resolved in areas where Dash doesn't yet have Bitcoin's address type warnings functionality

Original Bitcoin PR:

bitcoin#27279

Bitcoin commit: 6a16732

Test plan

  • Build succeeds
  • Functional tests pass: test/functional/wallet_createwallet.py
  • RPC help shows new warnings array field
  • Verify backwards compatibility with deprecated warning field when -deprecatedrpc=walletwarningfield is set

Generated with Claude Code

Summary by CodeRabbit

  • New Features

    • Wallet RPCs now return a “warnings” array for clearer, multi-message guidance across create, load, unload, restore, and import operations.
    • Unloadwallet now returns a structured result with optional warnings.
  • Bug Fixes

    • Improved node robustness during reindex when encountering read-only block files.
  • Documentation

    • Deprecation notice: “warning” field in wallet RPCs will be removed in v26. Use “warnings” array. Temporary opt-in via -deprecatedrpc=walletwarningfield.
  • Tests

    • Added functional tests for reindexing with read-only block files and for wallet creation warnings behavior.

…s already there

dfcef53 blockstorage: do not flush block to disk if it is already there (Matthew Zipkin)

Pull request description:

  Closes bitcoin#2039

  When reindexing from flat-file block storage there is no need to write anything back to disk, since the block data is already there. This PR skips flushing to disk those blocks that already have a known position in the datastore. Skipping this means that users can write-protect the `blk` files on disk which may be useful for security or even safely sharing that data between multiple bitcoind instances.

  `FindBlockPos()` may also flush the undo data file, but again this is skipped if the corresponding block position is known, like during the initial stage of a reindex when block data is being indexed. Once the block index is complete the validation mechanism will call `ConnectBlock()` which will save undo data at that time.

  The call stack looks like this:

  ```
  init()
  ThreadImport() <-- process fReindex flag
  LoadExternalBlockFile()
  AcceptBlock()
  SaveBlockToDisk()
  FindBlockPos()
  FlushBlockFile() <-- unnecessary if block is already on disk
  ```

  A larger refactor of this part of the code was started by mzumsande here:  https://github.com/mzumsande/bitcoin/tree/202207_refactor_findblockpos including this fix, reviewers can let me know if the changes should be combined.

ACKs for top commit:
  sipa:
    utACK dfcef53
  mzumsande:
    re-ACK dfcef53
  achow101:
    ACK dfcef53
  furszy:
    Rebase diff ACK dfcef53.

Tree-SHA512: 385c5ac1288b325135398d0ddd3ab788fa98cc0ca19bd2474c74039f2ce70d5088c1d1c9d4dd10aefcbd4c757767ec5805d07ba8cee9289a66f96e6f9eaa5279
…oad,unload,restore}wallet

7ccdd74 test: fix importmulti/importdescriptors assertion (Jon Atack)
19d888c rpc: move WALLET_FLAG_CAVEATS to the compilation unit of its caller (Jon Atack)
01df011 doc: release note for wallet RPCs "warning" field deprecation (Jon Atack)
9ea8b37 test: createwallet "warning" field deprecation test (Jon Atack)
645d7f7 rpc: deprecate "warning" field in {create,load,unload,restore}wallet (Jon Atack)
2f4a926 test: add test coverage for "warnings" field in createwallet (Jon Atack)
4a1e479 rpc: add "warnings" field to RPCs {create,load,unload,restore}wallet (Jon Atack)
079d8cd rpc: extract wallet "warnings" fields to a util helper (Jon Atack)
f73782a doc: fix/improve warning helps in {create,load,unload,restore}wallet (Jon Atack)

Pull request description:

  Based on discussion and concept ACKed in bitcoin#27138, add a `warnings` field to RPCs createwallet, loadwallet, unloadwallet, and restorewallet as a JSON array of strings to replace the `warning` string field in these 4 RPCs. The idea is to more gracefully handle multiple warning messages and for consistency with other wallet RPCs.  Then, deprecate the latter fields, which represent all the remaining RPC `warning` fields.

  The first commit bitcoin@f73782a implements bitcoin#27138 (comment) as an alternative to bitcoin#27138. One of those two could potentially be backported to our currently supported releases.

ACKs for top commit:
  achow101:
    ACK 7ccdd74
  1440000bytes:
    utACK bitcoin@7ccdd74
  vasild:
    ACK 7ccdd74
  pinheadmz:
    re-ACK 7ccdd74

Tree-SHA512: 314e0a4c41fa383d95e2817bfacf359d449e460529d235c3eb902851e2f4eacbabe646d9a5a4beabc4964cdfabf6397ed8301366a58d344a2f787f83b75e9d64
@cursor
Copy link

cursor bot commented Sep 30, 2025

You have run out of free Bugbot PR reviews for this billing cycle. This will reset on October 7.

To receive reviews on all of your PRs, visit the Cursor dashboard to activate Pro and start your 14-day free trial.

@coderabbitai
Copy link

coderabbitai bot commented Sep 30, 2025

Walkthrough

Introduces a new RPC warnings array and deprecates the legacy single warning field across wallet RPCs. Adds PushWarnings helpers, updates wallet RPC implementations and tests accordingly, adjusts block file flushing to reference a specific file index, removes a wallet flag caveats symbol, and adds a reindex-with-readonly-blockfile functional test.

Changes

Cohort / File(s) Summary of changes
Documentation
doc/release-notes-27279.md
Adds release note: wallet RPCs will replace "warning" with "warnings" array; deprecation flag -deprecatedrpc=walletwarningfield; removal slated for v26.
RPC utilities: warnings helpers
src/rpc/util.h, src/rpc/util.cpp
Adds PushWarnings overloads to attach a "warnings" array to RPC results; includes internal conversion from std::vector<bilingual_str> to UniValue.
Wallet RPC: warnings adoption and deprecation handling
src/wallet/rpc/wallet.cpp, src/wallet/rpc/backup.cpp
Refactors RPC results to use "warnings" array; conditionally include legacy "warning" when walletwarningfield deprecated RPC is enabled; updates help/results; incremental result construction.
Wallet core: caveats symbol removal
src/wallet/wallet.h, src/wallet/wallet.cpp
Removes public WALLET_FLAG_CAVEATS declaration and definition.
Node block storage
src/node/blockstorage.cpp
Updates FindBlockPos to call FlushBlockFile with previous file index; logs warning on flush failure; removes old two-argument call.
Functional test: reindex with readonly block file
test/functional/feature_reindex_readonly.py
Adds test to verify -reindex succeeds when an earlier block file is read-only/immutable; handles platform-specific attribute toggling.
Functional test: wallet creation warnings
test/functional/wallet_createwallet.py
Updates tests to validate "warnings" array; adds constants for expected messages; enables and then disables legacy "warning" via -deprecatedrpc=walletwarningfield; adds legacy wallet checks when BDB is available.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~60 minutes

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 12.50% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The title clearly and succinctly summarizes the primary change—adding a new “warnings” array and deprecating the existing “warning” field in the createwallet, loadwallet, unloadwallet, and restorewallet RPCs—so a reviewer can immediately understand the core update without extraneous detail.
✨ Finishing touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch backport-0.25-batch-412-pr-27279

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 Ruff (0.13.1)
test/functional/feature_reindex_readonly.py

�[1;31mruff failed�[0m
�[1mCause:�[0m Failed to load configuration /ruff.toml
�[1mCause:�[0m Failed to parse /ruff.toml
�[1mCause:�[0m TOML parse error at line 26, column 3
|
26 | "RSE100", # Use of assert detected
| ^^^^^^^^
Unknown rule selector: RSE100

test/functional/wallet_createwallet.py

�[1;31mruff failed�[0m
�[1mCause:�[0m Failed to load configuration /ruff.toml
�[1mCause:�[0m Failed to parse /ruff.toml
�[1mCause:�[0m TOML parse error at line 26, column 3
|
26 | "RSE100", # Use of assert detected
| ^^^^^^^^
Unknown rule selector: RSE100


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 3

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
test/functional/feature_reindex_readonly.py (1)

1-91: VALIDATION CONCERN: File appears unrelated to PR bitcoin#27279 scope.

This test file (feature_reindex_readonly.py) tests reindexing behavior with read-only block files, which is unrelated to the stated PR objective of adding a "warnings" array field and deprecating the "warning" string field in wallet RPCs.

Bitcoin Core PR bitcoin#27279 focuses on wallet RPC warning handling changes. This reindex test appears to be from a different Bitcoin commit or PR mixed into this backport batch.

Please verify:

  1. Is this file part of the original Bitcoin PR bitcoin#27279, or was it accidentally included from a different PR in the backport batch?
  2. If this is intentional (part of batch-412), the PR description should clarify which Bitcoin commit this test originates from.

Based on learnings about scope creep detection in Dash backports.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: ASSERTIVE

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 54e2588 and eda81aa.

📒 Files selected for processing (10)
  • doc/release-notes-27279.md (1 hunks)
  • src/node/blockstorage.cpp (1 hunks)
  • src/rpc/util.cpp (1 hunks)
  • src/rpc/util.h (1 hunks)
  • src/wallet/rpc/backup.cpp (4 hunks)
  • src/wallet/rpc/wallet.cpp (8 hunks)
  • src/wallet/wallet.cpp (0 hunks)
  • src/wallet/wallet.h (0 hunks)
  • test/functional/feature_reindex_readonly.py (1 hunks)
  • test/functional/wallet_createwallet.py (4 hunks)
💤 Files with no reviewable changes (2)
  • src/wallet/wallet.cpp
  • src/wallet/wallet.h
🧰 Additional context used
📓 Path-based instructions (4)
src/**/*.{cpp,h,cc,cxx,hpp}

📄 CodeRabbit inference engine (CLAUDE.md)

C++20 codebase should be placed under src/

Files:

  • src/rpc/util.h
  • src/wallet/rpc/backup.cpp
  • src/rpc/util.cpp
  • src/node/blockstorage.cpp
  • src/wallet/rpc/wallet.cpp
**

⚙️ CodeRabbit configuration file

**: # CodeRabbit AI Review Instructions for Dash Backports

Your Role

You are reviewing Bitcoin Core backports to Dash Core. Your ONLY job is to validate that the Dash commit faithfully represents the original Bitcoin commit with minimal, necessary adaptations.

Critical Validation Rules

1. File Operations Must Match (AUTO-REJECT if violated)

  • If Bitcoin modifies an existing file → Dash MUST modify (not create new)
  • If Bitcoin creates a new file → Dash creates
  • If Bitcoin deletes a file → Dash deletes
  • Common failure: Bitcoin modifies keys.txt, Dash creates new file with 58 keys

2. Size Ratio Check (80-150% of Bitcoin)

  • Count functional lines changed (exclude comments/whitespace)
  • Dash changes should be 80-150% of Bitcoin's size
  • Red flag: 2-line Bitcoin fix becoming 150+ lines in Dash

3. No Scope Creep

  • Reject if you see: "TODO:", "FIXME:", "while we're here", "also fix"
  • No unrelated refactoring or style changes
  • Only Bitcoin's intended changes + minimal Dash adaptations

4. Bitcoin-Specific Code Detection

  • Auto-reject witness/segwit code: msg_wtxidrelay, MSG_WTX, witness imports
  • Auto-reject RBF (replace-by-fee) functionality
  • Note: PSBT is supported in Dash (don't flag)

5. Mandatory Adaptations Only

  • bitcoindash in strings/paths
  • BitcoinDash in user-facing text
  • Port numbers: 8332→9998 (RPC), 8333→9999 (P2P)
  • Hardcoded test values specific to Dash
  • No other changes unless absolutely required

6. Completeness Check

  • All files changed in Bitcoin must be present
  • Extra files need clear justification (Dash-specific compatibility)
  • Missing files = incomplete backport

Review Process

  1. First: Check file operations match exactly
  2. Second: Calculate size ratio
  3. Third: Scan for scope creep patterns
  4. Fourth: Detect Bitcoin-specific code
  5. Fifth: Verify all changes are minimal adaptations

Output Format

VALIDATION: [PASS/FAIL]

File Operatio...

Files:

  • src/rpc/util.h
  • src/wallet/rpc/backup.cpp
  • doc/release-notes-27279.md
  • test/functional/wallet_createwallet.py
  • src/rpc/util.cpp
  • src/node/blockstorage.cpp
  • src/wallet/rpc/wallet.cpp
  • test/functional/feature_reindex_readonly.py
doc/**

📄 CodeRabbit inference engine (CLAUDE.md)

Unless specifically prompted, avoid making changes to the doc directory (documentation)

Files:

  • doc/release-notes-27279.md
test/functional/**/*.py

📄 CodeRabbit inference engine (CLAUDE.md)

Functional tests should be placed in test/functional/ and written in Python

Files:

  • test/functional/wallet_createwallet.py
  • test/functional/feature_reindex_readonly.py
🧠 Learnings (1)
📓 Common learnings
Learnt from: DashCoreAutoGuix
PR: DashCoreAutoGuix/dash#0
File: :0-0
Timestamp: 2025-07-31T01:14:55.631Z
Learning: DashCoreAutoGuix successfully completed a complex Bitcoin Core backport (PR #29412) for block mutation detection by implementing the IsBlockMutated function, adding net processing integration, creating comprehensive unit tests, and properly adapting all Bitcoin-specific witness code for Dash compatibility. The backport maintains full security functionality while respecting Dash's non-witness transaction architecture.
Learnt from: DashCoreAutoGuix
PR: DashCoreAutoGuix/dash#0
File: :0-0
Timestamp: 2025-07-28T20:34:29.061Z
Learning: During Dash backport verification of Bitcoin Core commit 06d469c26b, scope creep was detected when additional pruning test functionality was added to interface_usdt_utxocache.py beyond what was in the original Bitcoin commit. The fix involved removing the extra test block while maintaining the core compiler flag fixes for USDT compilation errors.
🧬 Code graph analysis (6)
src/rpc/util.h (1)
src/rpc/util.cpp (6)
  • PushWarnings (1054-1058)
  • PushWarnings (1054-1054)
  • PushWarnings (1060-1064)
  • PushWarnings (1060-1060)
  • obj (306-306)
  • obj (312-312)
src/wallet/rpc/backup.cpp (2)
src/rpc/util.cpp (6)
  • PushWarnings (1054-1058)
  • PushWarnings (1054-1054)
  • PushWarnings (1060-1064)
  • PushWarnings (1060-1060)
  • obj (306-306)
  • obj (312-312)
src/util/translation.h (1)
  • Untranslated (48-48)
test/functional/wallet_createwallet.py (2)
test/functional/test_framework/test_framework.py (2)
  • BitcoinTestFramework (101-1137)
  • is_bdb_compiled (1135-1137)
src/wallet/rpc/wallet.cpp (2)
  • createwallet (618-715)
  • createwallet (618-618)
src/rpc/util.cpp (1)
src/wallet/rpc/backup.cpp (4)
  • warnings (1162-1162)
  • warnings (1297-1297)
  • warnings (1383-1383)
  • warnings (1665-1665)
src/wallet/rpc/wallet.cpp (2)
src/rpc/util.cpp (8)
  • HelpExampleCli (204-207)
  • HelpExampleCli (204-204)
  • HelpExampleRpc (222-227)
  • HelpExampleRpc (222-222)
  • PushWarnings (1054-1058)
  • PushWarnings (1054-1054)
  • PushWarnings (1060-1064)
  • PushWarnings (1060-1060)
src/util/translation.h (1)
  • Untranslated (48-48)
test/functional/feature_reindex_readonly.py (2)
test/functional/test_framework/test_framework.py (1)
  • start_node (646-655)
test/functional/test_framework/test_node.py (2)
  • chain_path (429-430)
  • wait_for_debug_log (473-506)
🪛 Flake8 (7.2.0)
test/functional/feature_reindex_readonly.py

[error] 37-37: do not assign a lambda expression, use a def

(E731)


[error] 43-43: do not assign a lambda expression, use a def

(E731)


[error] 62-62: do not assign a lambda expression, use a def

(E731)

🪛 markdownlint-cli2 (0.18.1)
doc/release-notes-27279.md

1-1: First line in a file should be a top-level heading

(MD041, first-line-heading, first-line-h1)

🔇 Additional comments (15)
test/functional/wallet_createwallet.py (6)

18-20: LGTM! Constants defined for warning message validation.

These constants centralize the expected warning messages for easier maintenance and consistent validation across tests.


25-25: LGTM! Deprecated RPC flag enables backward compatibility testing.

Adding -deprecatedrpc=walletwarningfield allows the test to verify both the deprecated "warning" string field and the new "warnings" array field are present during the transition period.


60-60: LGTM! Updated to check new "warnings" array field.

Correctly validates that the "warnings" array field is not present in error responses when private keys are disabled, consistent with the new API structure.


165-167: LGTM! Validates both deprecated and new warning formats.

The test correctly verifies:

  1. The deprecated "warning" string field (with newline-delimited messages)
  2. The new "warnings" array field (with separate array elements)

This ensures backward compatibility during the deprecation transition.


180-193: LGTM! Legacy wallet deprecation test properly guarded.

The test block correctly:

  1. Guards legacy wallet testing with is_bdb_compiled() check
  2. Tests legacy wallet creation warning messages
  3. Validates both single and combined warning scenarios
  4. Verifies both "warning" (deprecated) and "warnings" (array) formats

195-199: LGTM! Verifies deprecated field removal.

Correctly tests that the deprecated "warning" field is not present after restarting the node without the -deprecatedrpc=walletwarningfield flag, ensuring the deprecation mechanism works as intended.

src/wallet/rpc/wallet.cpp (9)

27-27: LGTM! Required include added.

The wallet/walletutil.h include is necessary for wallet utility functions used in the warning handling implementation.


39-44: LGTM! Wallet flag caveats map introduced.

This static map provides warning messages for specific wallet flags, currently containing the AVOID_REUSE flag caveat about rescanning. This centralizes warning logic and supports the new warnings array field.


500-521: LGTM! loadwallet help text updated with warnings fields.

The help text correctly documents:

  1. The deprecated "warning" string field (with deprecation note)
  2. The new "warnings" array field
  3. The -deprecatedrpc=walletwarningfield configuration requirement

Help examples also updated appropriately. Note: "dashd" is correctly used instead of "bitcoind".


540-543: LGTM! loadwallet implementation adds conditional warnings.

The implementation correctly:

  1. Checks rpcEnableDeprecated("walletwarningfield") before adding deprecated "warning" field
  2. Uses Join() with newline delimiter for backward compatibility
  3. Calls PushWarnings() to add the new "warnings" array field

609-611: LGTM! setwalletflag uses new caveats map.

Correctly references WALLET_FLAG_CAVEATS to retrieve warning messages for wallet flags, maintaining consistency with the new warning infrastructure.


636-640: LGTM! createwallet help text updated with warnings fields.

Documentation correctly describes both the deprecated "warning" string field and new "warnings" array field, consistent with the pattern established in loadwallet.


707-710: LGTM! createwallet implementation adds conditional warnings.

Follows the same correct pattern as loadwallet:

  1. Conditional deprecated "warning" field based on rpcEnableDeprecated("walletwarningfield")
  2. Newline-delimited warning string for backward compatibility
  3. PushWarnings() call for new "warnings" array

720-736: LGTM! unloadwallet help updated with object result and warnings.

Help text correctly updated to:

  1. Improve parameter descriptions
  2. Change result type from null to object
  3. Document both deprecated "warning" and new "warnings" fields
  4. Update examples

769-776: LGTM! unloadwallet returns object with warnings.

Implementation correctly:

  1. Creates UniValue object result instead of returning null
  2. Adds conditional deprecated "warning" field
  3. Calls PushWarnings() for new "warnings" array
  4. Returns the result object after unloading wallet

Comment on lines +9 to +10
deprecation period by launching bitcoind with the configuration option
`-deprecatedrpc=walletwarningfield`. (#27279)
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

Replace upstream daemon name with Dash variant.

Line 9 still tells users to launch “bitcoind”, but in Dash this should read “dashd”. Please adjust the release note so Dash operators follow the correct instructions.

🤖 Prompt for AI Agents
In doc/release-notes-27279.md around lines 9 to 10, the release note references
the upstream daemon name "bitcoind" but Dash operators should be instructed to
run "dashd"; update the wording to replace "bitcoind" with "dashd" (e.g.,
"launch dashd with the configuration option
`-deprecatedrpc=walletwarningfield`") so the correct daemon name appears in the
release note.

Comment on lines +652 to +656
if (!FlushBlockFile(m_last_blockfile, !fKnown, finalize_undo)) {
LogPrintLevel(BCLog::BLOCKSTORE, BCLog::Level::Warning,
"Failed to flush previous block file %05i (finalize=%i, finalize_undo=%i) before opening new block file %05i\n",
m_last_blockfile, !fKnown, finalize_undo, nFile);
}
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🔴 Critical

FlushBlockFile call uses a non-existent signature.

Line 652 invokes FlushBlockFile(m_last_blockfile, !fKnown, finalize_undo) and checks its return value, but in this tree BlockManager::FlushBlockFile is still declared as void FlushBlockFile(bool fFinalize, bool finalize_undo) (see Line 557). This won’t compile—the extra m_last_blockfile argument doesn’t match any overload, and there’s no boolean return to test. Please port the corresponding signature/body change from the upstream commit (accepting the file index and returning a status) or revert the call form so the build succeeds.

🤖 Prompt for AI Agents
In src/node/blockstorage.cpp around lines 652-656, the call
FlushBlockFile(m_last_blockfile, !fKnown, finalize_undo) does not match the
current BlockManager::FlushBlockFile(bool fFinalize, bool finalize_undo)
signature and incorrectly checks a return value; fix by porting the upstream
signature change or reverting the call: either (A) update
BlockManager::FlushBlockFile declaration and definition to accept the file index
(e.g. int file) and return a status/boolean (update all callers to handle the
return), then call FlushBlockFile(m_last_blockfile, !fKnown, finalize_undo) and
check the returned status; or (B) change this site to call the existing API
(FlushBlockFile(!fKnown, finalize_undo)) and remove the boolean return check,
leaving logging based on void behavior — apply the corresponding header/source
edits and update any other callers to match the chosen API.

filename = self.nodes[0].chain_path / "blocks" / "blk00000.dat"
filename.chmod(stat.S_IREAD)

undo_immutable = lambda: None
Copy link

Choose a reason for hiding this comment

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

🧹 Nitpick | 🔵 Trivial

Replace lambda assignments with def statements.

Flake8 correctly flags these lambda assignments as violating PEP 8 style (E731). Use named functions instead for better readability and debuggability.

Apply these changes:

-    undo_immutable = lambda: None
+    def undo_immutable():
+        pass
-                subprocess.run(['chattr', '+i', filename], capture_output=True, check=True)
-                undo_immutable = lambda: subprocess.check_call(['chattr', '-i', filename])
+                def undo_immutable_chattr():
+                    subprocess.check_call(['chattr', '-i', filename])
+                subprocess.run(['chattr', '+i', filename], capture_output=True, check=True)
+                undo_immutable = undo_immutable_chattr
-                subprocess.run(['chflags', 'uchg', filename], capture_output=True, check=True)
-                undo_immutable = lambda: subprocess.check_call(['chflags', 'nouchg', filename])
+                def undo_immutable_chflags():
+                    subprocess.check_call(['chflags', 'nouchg', filename])
+                subprocess.run(['chflags', 'uchg', filename], capture_output=True, check=True)
+                undo_immutable = undo_immutable_chflags

As per static analysis hints.

Also applies to: 43-43, 62-62

🧰 Tools
🪛 Flake8 (7.2.0)

[error] 37-37: do not assign a lambda expression, use a def

(E731)

🤖 Prompt for AI Agents
In test/functional/feature_reindex_readonly.py around lines 37, 43 and 62,
replace the inline lambda assignments (e.g. undo_immutable = lambda: None) with
properly named def functions to satisfy PEP8 E731 and improve
readability/debuggability; create simple def undo_immutable(): return None (and
similar named defs for the other two lambda assignments), then assign or use
those function names where the lambdas were used.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants