docstring-generator-ext 2.0.3__tar.gz → 2.0.4__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.3 → docstring_generator_ext-2.0.4}/PKG-INFO +1 -1
  2. {docstring_generator_ext-2.0.3 → docstring_generator_ext-2.0.4}/docstring_generator_ext.egg-info/PKG-INFO +1 -1
  3. {docstring_generator_ext-2.0.3 → docstring_generator_ext-2.0.4}/pyproject.toml +1 -1
  4. {docstring_generator_ext-2.0.3 → docstring_generator_ext-2.0.4}/src/FunctionFormat.cpp +56 -27
  5. {docstring_generator_ext-2.0.3 → docstring_generator_ext-2.0.4}/src/FunctionFormat.hpp +26 -0
  6. {docstring_generator_ext-2.0.3 → docstring_generator_ext-2.0.4}/src/NumpyDocstring.cpp +0 -4
  7. {docstring_generator_ext-2.0.3 → docstring_generator_ext-2.0.4}/src/parser.cpp +4 -3
  8. {docstring_generator_ext-2.0.3 → docstring_generator_ext-2.0.4}/src/parser.hpp +0 -1
  9. {docstring_generator_ext-2.0.3 → docstring_generator_ext-2.0.4}/MANIFEST.in +0 -0
  10. {docstring_generator_ext-2.0.3 → docstring_generator_ext-2.0.4}/README.md +0 -0
  11. {docstring_generator_ext-2.0.3 → docstring_generator_ext-2.0.4}/docstring_generator_ext.egg-info/SOURCES.txt +0 -0
  12. {docstring_generator_ext-2.0.3 → docstring_generator_ext-2.0.4}/docstring_generator_ext.egg-info/dependency_links.txt +0 -0
  13. {docstring_generator_ext-2.0.3 → docstring_generator_ext-2.0.4}/docstring_generator_ext.egg-info/requires.txt +0 -0
  14. {docstring_generator_ext-2.0.3 → docstring_generator_ext-2.0.4}/docstring_generator_ext.egg-info/top_level.txt +0 -0
  15. {docstring_generator_ext-2.0.3 → docstring_generator_ext-2.0.4}/setup.cfg +0 -0
  16. {docstring_generator_ext-2.0.3 → docstring_generator_ext-2.0.4}/setup.py +0 -0
  17. {docstring_generator_ext-2.0.3 → docstring_generator_ext-2.0.4}/src/GoogleDocstring.cpp +0 -0
  18. {docstring_generator_ext-2.0.3 → docstring_generator_ext-2.0.4}/src/GoogleDocstring.hpp +0 -0
  19. {docstring_generator_ext-2.0.3 → docstring_generator_ext-2.0.4}/src/IDocstringFormat.cpp +0 -0
  20. {docstring_generator_ext-2.0.3 → docstring_generator_ext-2.0.4}/src/IDocstringFormat.hpp +0 -0
  21. {docstring_generator_ext-2.0.3 → docstring_generator_ext-2.0.4}/src/NumpyDocstring.hpp +0 -0
  22. {docstring_generator_ext-2.0.3 → docstring_generator_ext-2.0.4}/src/ReStructuredDocstring.cpp +0 -0
  23. {docstring_generator_ext-2.0.3 → docstring_generator_ext-2.0.4}/src/ReStructuredDocstring.hpp +0 -0
  24. {docstring_generator_ext-2.0.3 → docstring_generator_ext-2.0.4}/src/docComparator.cpp +0 -0
  25. {docstring_generator_ext-2.0.3 → docstring_generator_ext-2.0.4}/src/docComparator.hpp +0 -0
  26. {docstring_generator_ext-2.0.3 → docstring_generator_ext-2.0.4}/src/docstringFormat.cpp +0 -0
  27. {docstring_generator_ext-2.0.3 → docstring_generator_ext-2.0.4}/src/docstringFormat.hpp +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: docstring_generator_ext
3
- Version: 2.0.3
3
+ Version: 2.0.4
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.3
3
+ Version: 2.0.4
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.3"
3
+ version = "2.0.4"
4
4
  description = "Generate Docstrings with type-hint information."
5
5
  authors = [
6
6
  { name = "FelixTheC", email = "fberndt87@gmail.com" },
@@ -4,12 +4,12 @@
4
4
  #include "parser.hpp"
5
5
 
6
6
  const std::map<std::string, ParameterKind> ParameterKinds = {
7
- {"argument", ParameterKind::ARG},
8
- {"positional only argument", ParameterKind::POS_ONLY},
9
- {"keyword only argument", ParameterKind::KW_ONLY},
10
- {"variadic argument", ParameterKind::VARIADIC_ARG},
11
- {"keyword arguments", ParameterKind::KEYWORD_ARG},
12
- };
7
+ {"argument", ParameterKind::ARG},
8
+ {"positional only argument", ParameterKind::POS_ONLY},
9
+ {"keyword only argument", ParameterKind::KW_ONLY},
10
+ {"variadic argument", ParameterKind::VARIADIC_ARG},
11
+ {"keyword arguments", ParameterKind::KEYWORD_ARG},
12
+ };
13
13
 
14
14
 
15
15
  ParameterKind from_str(const std::string &kind) {
@@ -37,6 +37,24 @@ std::ostream &operator<<(std::ostream &out, ParameterKind const &obj) noexcept {
37
37
  return out;
38
38
  }
39
39
 
40
+ std::string parameter_kind::to_str(const ParameterKind &kind) {
41
+ std::string name = "UNKNOWN";
42
+ switch (kind) {
43
+ case ParameterKind::ARG: name = "Argument";
44
+ break;
45
+ case ParameterKind::POS_ONLY: name = "Positional only argument";
46
+ break;
47
+ case ParameterKind::KW_ONLY: name = "Keyword only argument";
48
+ break;
49
+ case ParameterKind::VARIADIC_ARG: name = "Variadic arguments";
50
+ break;
51
+ case ParameterKind::KEYWORD_ARG: name = "Keyword arguments";
52
+ break;
53
+ }
54
+
55
+ return name;
56
+ }
57
+
40
58
  void FunctionParameter::update_description(const std::string &descr, const DocstringFormatStyle &formatStyle) noexcept {
41
59
  switch (formatStyle) {
42
60
  case DocstringFormatStyle::reST:
@@ -61,7 +79,7 @@ void FunctionParameter::update_description(const std::string &descr) noexcept {
61
79
  auto start_pos = descr.find(kind_name);
62
80
 
63
81
  if (start_pos == std::string::npos)
64
- start_pos = 0;
82
+ start_pos = 0;
65
83
  else {
66
84
  start_pos += kind_name.size() + 2;
67
85
  }
@@ -157,20 +175,29 @@ void FunctionDocstring::detect_format_style() noexcept {
157
175
  bool could_be_google = false;
158
176
  bool could_be_rest = false;
159
177
 
160
- could_be_google = std::ranges::any_of(TypicalFormatStyle[1].second, [this](const auto &part) {
161
- return docstring.find(part) != std::string::npos;
162
- });
178
+ could_be_google = std::ranges::any_of(
179
+ TypicalFormatStyle[1].second,
180
+ [this](const auto &part) {
181
+ return docstring.find(part) != std::string::npos;
182
+ }
183
+ );
163
184
 
164
185
  // Numpy uses `Returns` as the keyword for the return value description and Google uses `Returns:` as the keyword for the return value description
165
186
  // so if it's not google, it could be numpy
166
187
  if (!could_be_google)
167
- could_be_numpy = std::ranges::any_of(TypicalFormatStyle[0].second, [this](const auto &part) {
168
- return docstring.find(part) != std::string::npos;
169
- });
188
+ could_be_numpy = std::ranges::any_of(
189
+ TypicalFormatStyle[0].second,
190
+ [this](const auto &part) {
191
+ return docstring.find(part) != std::string::npos;
192
+ }
193
+ );
170
194
 
171
- could_be_rest = std::ranges::any_of(TypicalFormatStyle[2].second, [this](const auto &part) {
172
- return docstring.find(part) != std::string::npos;
173
- });
195
+ could_be_rest = std::ranges::any_of(
196
+ TypicalFormatStyle[2].second,
197
+ [this](const auto &part) {
198
+ return docstring.find(part) != std::string::npos;
199
+ }
200
+ );
174
201
 
175
202
  const int total = could_be_numpy + could_be_google + could_be_rest;
176
203
 
@@ -194,23 +221,25 @@ void FunctionDocstring::detect_format_style() noexcept {
194
221
  if (!detected_format_style.has_value())
195
222
  return -1;
196
223
 
197
- const auto get_end_pos = [](std::string& _docstring, StyleSections sections) {
224
+ const auto get_end_pos = [](std::string &_docstring, StyleSections sections) {
198
225
  std::vector<size_t> res;
199
- std::ranges::for_each(sections, [&](const auto& line) {
226
+ std::ranges::for_each(
227
+ sections,
228
+ [&](const auto &line) {
200
229
  res.emplace_back(_docstring.find(line));
201
- });
230
+ }
231
+ );
202
232
  std::ranges::sort(res, std::less<>());
203
233
  return res[0];
204
234
  };
205
235
 
206
- switch (*detected_format_style)
207
- {
208
- case DocstringFormatStyle::NUMPY:
209
- return get_end_pos(docstring, TypicalFormatStyle[0].second);
210
- case DocstringFormatStyle::GOOGLE:
211
- return get_end_pos(docstring, TypicalFormatStyle[1].second);
212
- case DocstringFormatStyle::reST:
213
- return get_end_pos(docstring, TypicalFormatStyle[2].second);
236
+ switch (*detected_format_style) {
237
+ case DocstringFormatStyle::NUMPY:
238
+ return get_end_pos(docstring, TypicalFormatStyle[0].second);
239
+ case DocstringFormatStyle::GOOGLE:
240
+ return get_end_pos(docstring, TypicalFormatStyle[1].second);
241
+ case DocstringFormatStyle::reST:
242
+ return get_end_pos(docstring, TypicalFormatStyle[2].second);
214
243
  }
215
244
 
216
245
  return -1;
@@ -1,6 +1,7 @@
1
1
  #ifndef DOCSTRING_GENERATOR_EXT_FUNCTIONFORMAT_HPP
2
2
  #define DOCSTRING_GENERATOR_EXT_FUNCTIONFORMAT_HPP
3
3
 
4
+ #include <format>
4
5
  #include <map>
5
6
  #include <set>
6
7
  #include <string>
@@ -33,6 +34,31 @@ constexpr std::array<std::pair<std::string_view, StyleSections>, 3> TypicalForma
33
34
  ParameterKind from_str(const std::string &kind);
34
35
  std::ostream &operator<<(std::ostream &out, ParameterKind const &obj) noexcept;
35
36
 
37
+ namespace parameter_kind{
38
+ std::string to_str(const ParameterKind &kind);
39
+ }
40
+
41
+ template<>
42
+ struct std::formatter<ParameterKind> : std::formatter<std::string_view> {
43
+ // Format the enum by mapping it to a string_view
44
+ auto format(ParameterKind kind, std::format_context &ctx) const {
45
+ std::string_view name = "UNKNOWN";
46
+ switch (kind) {
47
+ case ParameterKind::ARG: name = "Argument";
48
+ break;
49
+ case ParameterKind::POS_ONLY: name = "Positional only argument";
50
+ break;
51
+ case ParameterKind::KW_ONLY: name = "Keyword only argument";
52
+ break;
53
+ case ParameterKind::VARIADIC_ARG: name = "Variadic arguments";
54
+ break;
55
+ case ParameterKind::KEYWORD_ARG: name = "Keyword arguments";
56
+ break;
57
+ }
58
+ return std::formatter<std::string_view>::format(name, ctx);
59
+ }
60
+ };
61
+
36
62
  struct FunctionParameter {
37
63
  std::string name;
38
64
  std::string default_value;
@@ -1,7 +1,3 @@
1
- //
2
- // Created by felix on 11.07.26.
3
- //
4
-
5
1
  #include "NumpyDocstring.hpp"
6
2
 
7
3
  #include "parser.hpp"
@@ -186,8 +186,8 @@ std::vector<FunctionParameter> generate_function_parameters(
186
186
  }
187
187
 
188
188
  std::string parameter_name = py::cast<std::string>(py::getattr(elem, "arg"));
189
- if (parameter_name == "self") {
190
- annotation_str = "object";
189
+ if (parameter_name == "self" || parameter_name == "cls") {
190
+ continue;
191
191
  }
192
192
 
193
193
  result.emplace_back(
@@ -364,7 +364,8 @@ void get_docstring_return_descr(FunctionInfo &functionInfo) noexcept {
364
364
  const auto end = functionInfo.docstring.docstring.find('\n', start);
365
365
  if (end != std::string::npos && start > 0) {
366
366
  functionInfo.returns.description = functionInfo.docstring.docstring.substr(start, end - start);
367
- functionInfo.docstring.docstring.erase(start - 2, functionInfo.returns.description.size() + 3); // 3 = '>>' + '\n'
367
+ functionInfo.docstring.docstring.erase(start - 2, functionInfo.returns.description.size() + 3);
368
+ // 3 = '>>' + '\n'
368
369
  }
369
370
  }
370
371
  }
@@ -2,7 +2,6 @@
2
2
  #define DOCSTRING_GENERATOR_EXT_PARSER_HPP
3
3
 
4
4
  #include <memory>
5
- #include <set>
6
5
  #include <string>
7
6
  #include <vector>
8
7
  #include "FunctionFormat.hpp"