Skip to content

Commit 1e7a510

Browse files
author
UnboundVariable
committed
Code review feedback.
1 parent d83b596 commit 1e7a510

File tree

3 files changed

+13
-31
lines changed

3 files changed

+13
-31
lines changed

crates/ty_ide/src/docstring.rs

Lines changed: 9 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -41,25 +41,19 @@ pub fn get_parameter_documentation(docstring: &str) -> HashMap<String, String> {
4141
let mut param_docs = HashMap::new();
4242

4343
// Google-style docstrings
44-
if let Some(google_docs) = extract_google_style_params(docstring) {
45-
param_docs.extend(google_docs);
46-
}
44+
param_docs.extend(extract_google_style_params(docstring));
4745

4846
// NumPy-style docstrings
49-
if let Some(numpy_docs) = extract_numpy_style_params(docstring) {
50-
param_docs.extend(numpy_docs);
51-
}
47+
param_docs.extend(extract_numpy_style_params(docstring));
5248

5349
// reST/Sphinx-style docstrings
54-
if let Some(rest_docs) = extract_rest_style_params(docstring) {
55-
param_docs.extend(rest_docs);
56-
}
50+
param_docs.extend(extract_rest_style_params(docstring));
5751

5852
param_docs
5953
}
6054

6155
/// Extract parameter documentation from Google-style docstrings.
62-
fn extract_google_style_params(docstring: &str) -> Option<HashMap<String, String>> {
56+
fn extract_google_style_params(docstring: &str) -> HashMap<String, String> {
6357
let mut param_docs = HashMap::new();
6458

6559
let mut in_args_section = false;
@@ -138,11 +132,7 @@ fn extract_google_style_params(docstring: &str) -> Option<HashMap<String, String
138132
param_docs.insert(param_name, current_doc.trim().to_string());
139133
}
140134

141-
if param_docs.is_empty() {
142-
None
143-
} else {
144-
Some(param_docs)
145-
}
135+
param_docs
146136
}
147137

148138
/// Calculate the indentation level of a line (number of leading whitespace characters)
@@ -151,7 +141,7 @@ fn get_indentation_level(line: &str) -> usize {
151141
}
152142

153143
/// Extract parameter documentation from NumPy-style docstrings.
154-
fn extract_numpy_style_params(docstring: &str) -> Option<HashMap<String, String>> {
144+
fn extract_numpy_style_params(docstring: &str) -> HashMap<String, String> {
155145
let mut param_docs = HashMap::new();
156146

157147
let mut lines = docstring
@@ -314,15 +304,11 @@ fn extract_numpy_style_params(docstring: &str) -> Option<HashMap<String, String>
314304
param_docs.insert(param_name, current_doc.trim().to_string());
315305
}
316306

317-
if param_docs.is_empty() {
318-
None
319-
} else {
320-
Some(param_docs)
321-
}
307+
param_docs
322308
}
323309

324310
/// Extract parameter documentation from reST/Sphinx-style docstrings.
325-
fn extract_rest_style_params(docstring: &str) -> Option<HashMap<String, String>> {
311+
fn extract_rest_style_params(docstring: &str) -> HashMap<String, String> {
326312
let mut param_docs = HashMap::new();
327313

328314
let mut current_param: Option<String> = None;
@@ -389,11 +375,7 @@ fn extract_rest_style_params(docstring: &str) -> Option<HashMap<String, String>>
389375
param_docs.insert(param_name, current_doc.trim().to_string());
390376
}
391377

392-
if param_docs.is_empty() {
393-
None
394-
} else {
395-
Some(param_docs)
396-
}
378+
param_docs
397379
}
398380

399381
#[cfg(test)]

crates/ty_python_semantic/src/types/call/bind.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2270,8 +2270,8 @@ impl<'db> Binding<'db> {
22702270

22712271
/// Returns a vector where each index corresponds to an argument position,
22722272
/// and the value is the parameter index that argument maps to (if any).
2273-
pub(crate) fn argument_to_parameter_mapping(&self) -> Box<[Option<usize>]> {
2274-
self.argument_parameters.clone()
2273+
pub(crate) fn argument_to_parameter_mapping(&self) -> &[Option<usize>] {
2274+
&self.argument_parameters
22752275
}
22762276
}
22772277

crates/ty_python_semantic/src/types/ide_support.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -393,7 +393,7 @@ pub struct CallSignatureDetails<'db> {
393393

394394
/// Mapping from argument indices to parameter indices. This helps
395395
/// determine which parameter corresponds to which argument position.
396-
pub argument_to_parameter_mapping: Box<[Option<usize>]>,
396+
pub argument_to_parameter_mapping: Vec<Option<usize>>,
397397
}
398398

399399
/// Extract signature details from a function call expression.
@@ -429,7 +429,7 @@ pub fn call_signature_details<'db>(
429429
parameter_label_offsets,
430430
parameter_names,
431431
definition: signature.definition(),
432-
argument_to_parameter_mapping: binding.argument_to_parameter_mapping(),
432+
argument_to_parameter_mapping: binding.argument_to_parameter_mapping().to_vec(),
433433
}
434434
})
435435
.collect()

0 commit comments

Comments
 (0)