docstring-generator-ext 2.0.10.post1__tar.gz → 2.0.11__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (27) hide show
  1. {docstring_generator_ext-2.0.10.post1 → docstring_generator_ext-2.0.11}/PKG-INFO +1 -1
  2. {docstring_generator_ext-2.0.10.post1 → docstring_generator_ext-2.0.11}/docstring_generator_ext.egg-info/PKG-INFO +1 -1
  3. {docstring_generator_ext-2.0.10.post1 → docstring_generator_ext-2.0.11}/pyproject.toml +1 -1
  4. {docstring_generator_ext-2.0.10.post1 → docstring_generator_ext-2.0.11}/src/FunctionFormat.cpp +4 -0
  5. {docstring_generator_ext-2.0.10.post1 → docstring_generator_ext-2.0.11}/src/FunctionFormat.hpp +1 -0
  6. {docstring_generator_ext-2.0.10.post1 → docstring_generator_ext-2.0.11}/src/parser.cpp +37 -17
  7. {docstring_generator_ext-2.0.10.post1 → docstring_generator_ext-2.0.11}/MANIFEST.in +0 -0
  8. {docstring_generator_ext-2.0.10.post1 → docstring_generator_ext-2.0.11}/README.md +0 -0
  9. {docstring_generator_ext-2.0.10.post1 → docstring_generator_ext-2.0.11}/docstring_generator_ext.egg-info/SOURCES.txt +0 -0
  10. {docstring_generator_ext-2.0.10.post1 → docstring_generator_ext-2.0.11}/docstring_generator_ext.egg-info/dependency_links.txt +0 -0
  11. {docstring_generator_ext-2.0.10.post1 → docstring_generator_ext-2.0.11}/docstring_generator_ext.egg-info/requires.txt +0 -0
  12. {docstring_generator_ext-2.0.10.post1 → docstring_generator_ext-2.0.11}/docstring_generator_ext.egg-info/top_level.txt +0 -0
  13. {docstring_generator_ext-2.0.10.post1 → docstring_generator_ext-2.0.11}/setup.cfg +0 -0
  14. {docstring_generator_ext-2.0.10.post1 → docstring_generator_ext-2.0.11}/setup.py +0 -0
  15. {docstring_generator_ext-2.0.10.post1 → docstring_generator_ext-2.0.11}/src/GoogleDocstring.cpp +0 -0
  16. {docstring_generator_ext-2.0.10.post1 → docstring_generator_ext-2.0.11}/src/GoogleDocstring.hpp +0 -0
  17. {docstring_generator_ext-2.0.10.post1 → docstring_generator_ext-2.0.11}/src/IDocstringFormat.cpp +0 -0
  18. {docstring_generator_ext-2.0.10.post1 → docstring_generator_ext-2.0.11}/src/IDocstringFormat.hpp +0 -0
  19. {docstring_generator_ext-2.0.10.post1 → docstring_generator_ext-2.0.11}/src/NumpyDocstring.cpp +0 -0
  20. {docstring_generator_ext-2.0.10.post1 → docstring_generator_ext-2.0.11}/src/NumpyDocstring.hpp +0 -0
  21. {docstring_generator_ext-2.0.10.post1 → docstring_generator_ext-2.0.11}/src/ReStructuredDocstring.cpp +0 -0
  22. {docstring_generator_ext-2.0.10.post1 → docstring_generator_ext-2.0.11}/src/ReStructuredDocstring.hpp +0 -0
  23. {docstring_generator_ext-2.0.10.post1 → docstring_generator_ext-2.0.11}/src/docComparator.cpp +0 -0
  24. {docstring_generator_ext-2.0.10.post1 → docstring_generator_ext-2.0.11}/src/docComparator.hpp +0 -0
  25. {docstring_generator_ext-2.0.10.post1 → docstring_generator_ext-2.0.11}/src/docstringFormat.cpp +0 -0
  26. {docstring_generator_ext-2.0.10.post1 → docstring_generator_ext-2.0.11}/src/docstringFormat.hpp +0 -0
  27. {docstring_generator_ext-2.0.10.post1 → docstring_generator_ext-2.0.11}/src/parser.hpp +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: docstring_generator_ext
3
- Version: 2.0.10.post1
3
+ Version: 2.0.11
4
4
  Summary: Generate Docstrings with type-hint information.
5
5
  Author-email: FelixTheC <fberndt87@gmail.com>
6
6
  Classifier: Environment :: Console
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: docstring_generator_ext
3
- Version: 2.0.10.post1
3
+ Version: 2.0.11
4
4
  Summary: Generate Docstrings with type-hint information.
5
5
  Author-email: FelixTheC <fberndt87@gmail.com>
6
6
  Classifier: Environment :: Console
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "docstring_generator_ext"
3
- version = "2.0.10.post1"
3
+ version = "2.0.11"
4
4
  description = "Generate Docstrings with type-hint information."
5
5
  authors = [
6
6
  { name = "FelixTheC", email = "fberndt87@gmail.com" },
@@ -133,6 +133,10 @@ void FunctionParameter::update_rest_description(const std::string &descr) noexce
133
133
  return docstring.start_line;
134
134
  }
135
135
 
136
+ if (body_start > 0) {
137
+ return static_cast<int>(body_start);
138
+ }
139
+
136
140
  if (returns.line_no > 0) {
137
141
  return static_cast<int>(returns.line_no + 1);
138
142
  }
@@ -106,6 +106,7 @@ struct FunctionException {
106
106
  struct FunctionInfo {
107
107
  std::vector<FunctionParameter> args{};
108
108
  uint32_t offset{};
109
+ uint64_t body_start{};
109
110
  FunctionDocstring docstring;
110
111
  FunctionReturn returns;
111
112
  std::set<FunctionException> exceptions {};
@@ -306,39 +306,51 @@ void get_docstring_arg_descr(FunctionInfo &functionInfo) noexcept {
306
306
  }
307
307
 
308
308
  auto start = functionInfo.docstring.docstring.find('$');
309
- if (start < std::string::npos) {
310
- auto end = functionInfo.docstring.docstring.find('\n', start + 1);
311
- std::string description;
312
-
313
- if (end >= std::string::npos) {
309
+ if (start != std::string::npos) {
310
+ // we need to check if this is a an expected placeholder
311
+ const auto end_placeholder = functionInfo.docstring.docstring.find(' ', start + 1);
312
+ const auto possible_placeholder_num = functionInfo.docstring.docstring.substr(start + 1, end_placeholder - start - 1);
313
+
314
+ if (possible_placeholder_num.empty() ||
315
+ !std::all_of(possible_placeholder_num.begin(), possible_placeholder_num.end(),
316
+ [](unsigned char c) { return std::isdigit(c); })) {
314
317
  return;
315
318
  }
316
319
 
320
+ int id = -1;
317
321
  try {
318
- description = functionInfo.docstring.docstring.substr(start, end - start);
319
- } catch (std::out_of_range &) {
322
+ id = std::stoi(possible_placeholder_num);
323
+ } catch (const std::exception &) {
320
324
  return;
321
325
  }
322
326
 
323
- auto end_id = description.find(' ');
324
- if (end_id == std::string::npos)
327
+ if (id < 0)
328
+ return;
329
+
330
+ auto end = functionInfo.docstring.docstring.find('\n', end_placeholder + 1);
331
+ if (end == std::string::npos) {
325
332
  return;
333
+ }
326
334
 
327
- int id = std::stoi(description.substr(1, end_id)) - 1;
335
+ std::string description;
336
+ description.reserve(end - start);
328
337
 
329
- if (static_cast<size_t>(id) < functionInfo.args.size()) {
338
+ try {
339
+ description = functionInfo.docstring.docstring.substr(end_placeholder + 1, end - end_placeholder - 1);
340
+ } catch (std::out_of_range &) {
341
+ return;
342
+ }
343
+
344
+ if (static_cast<size_t>(id - 1) < functionInfo.args.size()) {
330
345
  try {
331
- functionInfo.args[id].description = description.substr(end_id);
346
+ functionInfo.args[id - 1].description = description;
332
347
  } catch (std::out_of_range &) {
333
348
  return;
334
349
  }
335
350
 
336
- auto reduce = functionInfo.offset > 0 ? 2 * functionInfo.offset + 2 : 4 + 2;
337
-
338
351
  try {
339
352
  functionInfo.docstring.docstring.erase(
340
- start - reduce,
341
- end - start + reduce
353
+ start, description.size() + possible_placeholder_num.size() + 3
342
354
  );
343
355
  } catch (std::out_of_range &) {
344
356
  // no further action needed
@@ -461,8 +473,15 @@ std::optional<FunctionInfo> analyze_function(
461
473
  ) noexcept {
462
474
  std::vector<FunctionException> function_exceptions{};
463
475
 
476
+ uint64_t body_start = 0;
464
477
  if (py::hasattr(obj, "body")) {
465
478
  auto inner = py::getattr(obj, "body");
479
+ for (auto &elem: py::iter(inner)) {
480
+ if (py::hasattr(elem, "lineno")) {
481
+ body_start = py::cast<int>(py::getattr(elem, "lineno"));
482
+ break;
483
+ }
484
+ }
466
485
  get_exception(inner, ast_module, function_exceptions);
467
486
  }
468
487
 
@@ -479,7 +498,7 @@ std::optional<FunctionInfo> analyze_function(
479
498
  auto returns = py::getattr(obj, "returns");
480
499
 
481
500
  std::string return_str{};
482
- uint32_t return_end_line_no = 0;
501
+ uint32_t return_end_line_no = body_start;
483
502
 
484
503
  if (!returns.is_none()) {
485
504
  return_str = parse_ast_obj(returns, ast_module);
@@ -498,6 +517,7 @@ std::optional<FunctionInfo> analyze_function(
498
517
  FunctionInfo functionInfo{
499
518
  .args = f_args,
500
519
  .offset = offset,
520
+ .body_start = body_start,
501
521
  .docstring = doc_str,
502
522
  .returns = functionReturn,
503
523
  .exceptions = {}