-
Notifications
You must be signed in to change notification settings - Fork 21
Refactor filesystem_size_quartet method #1228
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
Conversation
Signed-off-by: mulhern <amulhern@redhat.com>
Adapt body of method accordingly Signed-off-by: mulhern <amulhern@redhat.com>
Also add type annotations for the method Signed-off-by: mulhern <amulhern@redhat.com>
WalkthroughType annotations were added across formatting and filesystem listing helpers. Function signatures were tightened, return types specified, and internal logic adjusted to handle None values explicitly. Table rendering helpers now use typed parameters. A new, typed filesystem_size_quartet helper was introduced and invoked with explicitly constructed Range values. Changes
Sequence Diagram(s)sequenceDiagram
autonumber
actor User
participant CLI as CLI Command
participant Table as Table.display
participant FS as filesystem_size_quartet
participant FMT as formatting.size_triple/print_table
User->>CLI: run list-filesystem
CLI->>Table: display()
Note over Table: Build rows with typed values<br/>total: Range, used?: Range, limit?: Range
Table->>FS: format quartet(total, used?, limit?)
FS-->>Table: "total / used / free / limit" string
Table->>FMT: print_table(headings, rows, alignment, file)
FMT-->>User: rendered table
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✨ Finishing touches
🧪 Generate unit tests
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. 🧪 Early access (Sonnet 4.5): enabledWe are currently testing the Sonnet 4.5 model, which is expected to improve code review quality. However, this model may lead to increased noise levels in the review comments. Please disable the early access features if the noise level causes any inconvenience. Note:
Comment |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
src/stratis_cli/_actions/_formatting.py(7 hunks)src/stratis_cli/_actions/_list_filesystem.py(2 hunks)
🧰 Additional context used
🧬 Code graph analysis (2)
src/stratis_cli/_actions/_list_filesystem.py (1)
src/stratis_cli/_actions/_formatting.py (2)
size_triple(39-56)get_property(59-73)
src/stratis_cli/_actions/_formatting.py (1)
src/stratis_cli/_actions/_physical.py (1)
size(103-114)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
- GitHub Check: test-runs (3.13)
- GitHub Check: test-runs (3.12)
🔇 Additional comments (10)
src/stratis_cli/_actions/_list_filesystem.py (2)
20-20: LGTM: Import addition supports new type annotations.The addition of
Optionalto the typing imports is necessary for the new type annotations in thefilesystem_size_quartetfunction signature.
127-136: LGTM: Function signature properly typed.The function signature now explicitly declares parameter and return types, improving type safety and code clarity. The implementation logic remains unchanged—it still uses
size_tripleand formats the limit appropriately.src/stratis_cli/_actions/_formatting.py (8)
20-20: LGTM: Import additions support new type annotations.The typing imports (
Callable,List,Optional) are necessary for the type annotations added throughout this file.
24-25: LGTM: D-Bus and justbytes imports support type annotations.The
Structimport from dbus andRangeimport from justbytes are needed for the explicit type annotations inget_propertyandsize_triplerespectively.
39-56: LGTM: Type annotations improve clarity.The addition of explicit type annotations to
size_triplemakes the function signature clearer. The logic correctly handles the case whereusedisNoneby settingfreetoNoneas well, which then displays asTABLE_FAILURE_STRINGin the formatted output.
59-73: LGTM: Type annotations align with D-Bus property handling.The type annotations correctly reflect that this function handles D-Bus Struct types (representing optional properties as
(bool, T)pairs) and returns either the transformed value or the default.
76-97: LGTM: Type annotations clarify integer parameters.The explicit type annotations make it clear that this function operates on integer measurements of column widths and character counts.
100-127: LGTM: Type annotations improve function signature clarity.The type annotations for
_print_rowmake the expected parameter types explicit. UsingAnyfor thefileparameter is appropriate since it accepts any file-like object with awritemethod.
129-171: LGTM: Type annotations enhance table printing interface.The type annotations clearly document the expected structure of the table data. The use of
List[str]for column headings and alignments, andList[Any]for row entries is appropriate given the flexible nature of table contents.
173-183: LGTM: Return type annotation documents formatter function.The return type
Callableclearly indicates this function returns a formatting function, improving the API documentation.
| filesystem_size_quartet( | ||
| Range(mofilesystem.Size()), | ||
| get_property(mofilesystem.Used(), Range, None), | ||
| get_property(mofilesystem.SizeLimit(), Range, None), | ||
| ), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion | 🟠 Major
🧩 Analysis chain
Verify that mofilesystem.Size() returns a value compatible with Range constructor.
The refactored call site now explicitly constructs Range(mofilesystem.Size()) instead of relying on implicit conversions. Ensure that mofilesystem.Size() returns a numeric value that the Range constructor accepts (likely an integer representing bytes).
🏁 Script executed:
#!/bin/bash
# Description: Verify the type signature of mofilesystem.Size() and its compatibility with Range constructor
# Search for MOFilesystem class and Size method definition
ast-grep --pattern $'class MOFilesystem {
$$$
Size($$$) {
$$$
}
$$$
}'
# Also search for Size method calls to understand return type
rg -nP --type=py -A3 'def Size\(' Length of output: 0
🏁 Script executed:
#!/bin/bash
# Locate MOFilesystem class definition
rg -nP 'class\s+MOFilesystem' -C3 -g '*.py'
# Locate any Size method definitions
rg -nP 'def\s+Size\(' -C3 -g '*.py'
# Locate Range class constructor
rg -nP 'class\s+Range' -C3 -g '*.py'
# Print top of list_filesystem action file for imports context
sed -n '1,50p' src/stratis_cli/_actions/_list_filesystem.pyLength of output: 1606
🏁 Script executed:
#!/bin/bash
# Print first part of the data module to locate MOFilesystem and its Size method
sed -n '1,200p' src/stratis_cli/_actions/_data.py
# Specifically search for the Size method in the data module
rg -nP 'def\s+Size\(' -C2 -g 'src/stratis_cli/_actions/_data.py'
# Inspect justbytes.Range constructor signature if installed
python3 - << 'EOF'
import inspect
try:
from justbytes import Range
print("Range signature:", inspect.signature(Range))
except Exception as e:
print("Error importing or inspecting Range:", e)
EOFLength of output: 5491
🏁 Script executed:
#!/bin/bash
# Locate interface spec for Filesystem in introspect module
grep -R 'org.storage.stratis3.Filesystem' -n src/stratis_cli/_actions/_introspect.py
# Print context around the Filesystem interface definition
sed -n '100,300p' src/stratis_cli/_actions/_introspect.pyLength of output: 8492
Convert MOFilesystem.Size() to int before passing to Range. The D-Bus Size property is defined as a string (type="s"), so MOFilesystem.Size() returns a str. Use Range(int(mofilesystem.Size())) to ensure the constructor receives a numeric value.
🤖 Prompt for AI Agents
In src/stratis_cli/_actions/_list_filesystem.py around lines 142 to 146, the
call passes MOFilesystem.Size() (a D-Bus string) into Range which expects a
numeric value; convert it to an int before constructing Range by calling
Range(int(mofilesystem.Size())), keeping the other get_property calls unchanged
so the filesystem_size_quartet receives a numeric Size.
Related #1225