diff options
| author | Jordan Wiens <github@psifertex.com> | 2025-11-06 16:36:05 -0500 |
|---|---|---|
| committer | Jordan Wiens <github@psifertex.com> | 2025-11-10 23:22:35 -0500 |
| commit | 36d99ad88aed9889c741f34bddd045405a68369b (patch) | |
| tree | c26ce3d073c08fb8e43e27942dbd9ea260e83fd6 | |
| parent | af815cd2e1ee9124288c9f73ef8f1254252643f3 (diff) | |
improved indentation and update formatting detection
| -rw-r--r-- | python/binaryview.py | 20 | ||||
| -rw-r--r-- | python/transform.py | 10 | ||||
| -rwxr-xr-x | scripts/check_docstring_formatting.py | 44 |
3 files changed, 51 insertions, 23 deletions
diff --git a/python/binaryview.py b/python/binaryview.py index aab64590..619d7592 100644 --- a/python/binaryview.py +++ b/python/binaryview.py @@ -2614,12 +2614,12 @@ class MemoryMap: The `source` parameter determines the type: - - `os.PathLike` or `str`: File path to be loaded into memory as a `DataMemoryRegion`. - - `bytes` or `bytearray`: Directly loaded into memory as a `DataMemoryRegion`. - - `databuffer.DataBuffer`: Loaded as a `DataMemoryRegion`. - - `fileaccessor.FileAccessor`: Remote proxy source. - - `BinaryView`: (Reserved for future). - - `None`: Creates an unbacked memory region (must specify `length`). + - `os.PathLike` or `str`: File path to be loaded into memory as a `DataMemoryRegion`. + - `bytes` or `bytearray`: Directly loaded into memory as a `DataMemoryRegion`. + - `databuffer.DataBuffer`: Loaded as a `DataMemoryRegion`. + - `fileaccessor.FileAccessor`: Remote proxy source. + - `BinaryView`: (Reserved for future). + - `None`: Creates an unbacked memory region (must specify `length`). .. note:: If no flags are specified and the new memory region overlaps with one or more existing regions, the overlapping portions of the new region will inherit the flags of the respective underlying regions. @@ -5209,10 +5209,10 @@ class BinaryView: **Thread Restrictions**: - - **Worker Threads**: This function cannot be called from a worker thread. If called from a worker thread, an error will be - logged, and the function will return immediately. - - **UI Threads**: This function cannot be called from a UI thread. If called from a UI thread, an error will be logged, and - the function will return immediately. + - **Worker Threads**: This function cannot be called from a worker thread. If called from a worker thread, an error will be + logged, and the function will return immediately. + - **UI Threads**: This function cannot be called from a UI thread. If called from a UI thread, an error will be logged, and + the function will return immediately. :rtype: None """ diff --git a/python/transform.py b/python/transform.py index 2b263911..9512b24b 100644 --- a/python/transform.py +++ b/python/transform.py @@ -447,11 +447,11 @@ class TransformContext: Each context can have: - - Input data (BinaryView) - - Transform information (name, parameters, results) - - File selection state (available_files, requested_files) - - Parent/child relationships for nested containers - - Extraction status and error messages + - Input data (BinaryView) + - Transform information (name, parameters, results) + - File selection state (available_files, requested_files) + - Parent/child relationships for nested containers + - Extraction status and error messages Contexts are typically accessed through a ``TransformSession`` rather than created directly. diff --git a/scripts/check_docstring_formatting.py b/scripts/check_docstring_formatting.py index 203be3d9..a3836e00 100755 --- a/scripts/check_docstring_formatting.py +++ b/scripts/check_docstring_formatting.py @@ -137,15 +137,43 @@ def check_docstring_formatting(docstring): prev_indent = len(prev_line) - len(prev_line.lstrip()) is_indented_continuation = current_indent > prev_indent - # Special case: >>> code blocks can have output lines between prompts - # If current line is >>> and previous line has same or greater indent (but isn't also >>>), - # it's likely output from previous command - is_code_output = (description == 'code block' and - prev_indent >= 0 and - not prev_line.strip().startswith('>>>') and - not prev_line.strip().startswith('...')) + # Special case for code blocks (>>>): + if description == 'code block': + # In Python interactive sessions, >>> prompts after output or continuations are normal + # Skip if: previous line is >>> or ..., OR both lines are indented (in code example) + if (prev_line.strip().startswith('...') or + prev_line.strip().startswith('>>>') or + (prev_indent > 0)): # Both lines indented = inside code example + # Don't report this as an issue + break - if not is_prev_list and not is_sphinx_field and not is_indented_continuation and not is_code_output: + # Special case for bullet/numbered lists: + # 1. Check if we're continuing a list (prev line is wrapped text from previous bullet) + # 2. Check if we're nested under another list item + is_nested_list = False + if description in ['bullet list item', 'numbered list item']: + # Look back to find context - skip blank lines + for j in range(i - 1, max(0, i - 10), -1): + check_line = lines[j] + if not check_line.strip(): + continue # Skip blank lines + check_indent = len(check_line) - len(check_line.lstrip()) + + # If we find a line at same indent that's also a list item, we're continuing a list + if check_indent == current_indent and any(re.match(p[0], check_line) for p in patterns): + is_nested_list = True # This is a list continuation + break + + # If we find a less-indented line that's also a list item, we're nested + if check_indent < current_indent and any(re.match(p[0], check_line) for p in patterns): + is_nested_list = True + break + + # If we find a non-list line at current or less indent (intro text), stop looking + if check_indent <= current_indent: + break + + if not is_prev_list and not is_sphinx_field and not is_indented_continuation and not is_nested_list: issues.append((i + 1, f"{description} without blank line before it")) break # Only report one issue per line |
