Skip to content

Commit 69dd672

Browse files
konardclaude
andcommitted
Fix lint and type errors in Python and Rust
Python: - Fix mypy Optional[str] type error in parse_indented - Fix ruff E712 comparison to True in experiment - Fix ruff E402 import order in experiment Rust: - Remove redundant else block in escape_reference - Add BuildHasher generic to format_indented for clippy - Convert match to let-else pattern in parse_indented 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <[email protected]>
1 parent 0200016 commit 69dd672

File tree

4 files changed

+14
-12
lines changed

4 files changed

+14
-12
lines changed

python/experiments/test_codec_simple.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
print(f"Encoded: {encoded}")
2323
decoded = decode(encoded)
2424
print(f"Decoded: {decoded}")
25-
print(f"Match: {decoded == True}")
25+
print(f"Match: {decoded is True}")
2626
except Exception as e:
2727
print(f"Error: {e}")
2828
import traceback

python/experiments/test_mutual_dicts.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"""Test mutual reference dicts."""
22

33
from link_notation_objects_codec import encode
4+
from links_notation import Parser
45

56
dict1 = {"name": "dict1"}
67
dict2 = {"name": "dict2"}
@@ -11,7 +12,6 @@
1112
print(f"Encoded: {encoded}")
1213

1314
# Parse it to see the structure
14-
from links_notation import Parser
1515

1616
parser = Parser()
1717
links = parser.parse(encoded)

python/src/link_notation_objects_codec/format.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,11 @@ def parse_indented(text: str) -> Tuple[str, Dict[str, Any]]:
202202
key.startswith('"') and key.endswith('"')
203203
):
204204
key = key[1:-1]
205-
unescaped_key = unescape_reference(key)
205+
unescaped_key_result = unescape_reference(key)
206+
# unescape_reference only returns None if input is None, but key is always str here
207+
unescaped_key: str = (
208+
unescaped_key_result if unescaped_key_result is not None else key
209+
)
206210

207211
# Parse value (remove surrounding quotes and unescape doubled quotes)
208212
if value.startswith('"') and value.endswith('"'):

rust/src/lib.rs

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -963,11 +963,10 @@ pub mod format {
963963
// Use double quotes, escape internal double quotes by doubling
964964
let escaped = value.replace('"', "\"\"");
965965
return format!("\"{}\"", escaped);
966-
} else {
967-
// Use single quotes, escape internal single quotes by doubling
968-
let escaped = value.replace('\'', "''");
969-
return format!("'{}'", escaped);
970966
}
967+
// Use single quotes, escape internal single quotes by doubling
968+
let escaped = value.replace('\'', "''");
969+
return format!("'{}'", escaped);
971970
}
972971

973972
// Just spaces or other special characters, use single quotes by default
@@ -1031,9 +1030,9 @@ pub mod format {
10311030
/// let result = format_indented("my-uuid", &obj, " ").unwrap();
10321031
/// assert!(result.starts_with("my-uuid\n"));
10331032
/// ```
1034-
pub fn format_indented(
1033+
pub fn format_indented<S: ::std::hash::BuildHasher>(
10351034
id: &str,
1036-
obj: &HashMap<String, String>,
1035+
obj: &HashMap<String, String, S>,
10371036
indent: &str,
10381037
) -> Result<String, FormatError> {
10391038
if id.is_empty() {
@@ -1139,9 +1138,8 @@ pub mod format {
11391138
}
11401139

11411140
// Find the first space that separates key from value
1142-
let space_index = match trimmed.find(' ') {
1143-
Some(i) => i,
1144-
None => continue, // No value, skip this line
1141+
let Some(space_index) = trimmed.find(' ') else {
1142+
continue; // No value, skip this line
11451143
};
11461144

11471145
let key = &trimmed[..space_index];

0 commit comments

Comments
 (0)