Coverage Report

Created: 2026-01-09 06:22

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/flatbuffers/include/codegen/python.h
Line
Count
Source
1
#ifndef FLATBUFFERS_INCLUDE_CODEGEN_PYTHON_H_
2
#define FLATBUFFERS_INCLUDE_CODEGEN_PYTHON_H_
3
4
#include <cstdint>
5
#include <set>
6
#include <string>
7
#include <vector>
8
9
#include "codegen/namer.h"
10
11
namespace flatbuffers {
12
namespace python {
13
static const Namer::Config kConfig = {
14
    /*types=*/Case::kKeep,
15
    /*constants=*/Case::kScreamingSnake,
16
    /*methods=*/Case::kUpperCamel,
17
    /*functions=*/Case::kUpperCamel,
18
    /*fields=*/Case::kLowerCamel,
19
    /*variable=*/Case::kLowerCamel,
20
    /*variants=*/Case::kKeep,
21
    /*enum_variant_seperator=*/".",
22
    /*escape_keywords=*/Namer::Config::Escape::AfterConvertingCase,
23
    /*namespaces=*/Case::kKeep,  // Packages in python.
24
    /*namespace_seperator=*/".",
25
    /*object_prefix=*/"",
26
    /*object_suffix=*/"T",
27
    /*keyword_prefix=*/"",
28
    /*keyword_suffix=*/"_",
29
    /*filenames=*/Case::kKeep,
30
    /*directories=*/Case::kKeep,
31
    /*output_path=*/"",
32
    /*filename_suffix=*/"",
33
    /*filename_extension=*/".py",
34
};
35
36
static const Namer::Config kStubConfig = {
37
    /*types=*/Case::kKeep,
38
    /*constants=*/Case::kScreamingSnake,
39
    /*methods=*/Case::kUpperCamel,
40
    /*functions=*/Case::kUpperCamel,
41
    /*fields=*/Case::kLowerCamel,
42
    /*variables=*/Case::kLowerCamel,
43
    /*variants=*/Case::kKeep,
44
    /*enum_variant_seperator=*/".",
45
    /*escape_keywords=*/Namer::Config::Escape::AfterConvertingCase,
46
    /*namespaces=*/Case::kKeep,  // Packages in python.
47
    /*namespace_seperator=*/".",
48
    /*object_prefix=*/"",
49
    /*object_suffix=*/"T",
50
    /*keyword_prefix=*/"",
51
    /*keyword_suffix=*/"_",
52
    /*filenames=*/Case::kKeep,
53
    /*directories=*/Case::kKeep,
54
    /*output_path=*/"",
55
    /*filename_suffix=*/"",
56
    /*filename_extension=*/".pyi",
57
};
58
59
// `Version` represent a Python version.
60
//
61
// The zero value (i.e. `Version{}`) represents both Python2 and Python3.
62
//
63
// https://docs.python.org/3/faq/general.html#how-does-the-python-version-numbering-scheme-work
64
struct Version {
65
  explicit Version(const std::string& version);
66
67
  bool IsValid() const;
68
69
  int16_t major = 0;
70
  int16_t minor = 0;
71
  int16_t micro = 0;
72
};
73
74
std::set<std::string> Keywords(const Version& version);
75
76
struct Import {
77
0
  bool IsLocal() const { return module == "."; }
78
79
  std::string module;
80
  std::string name;
81
};
82
83
struct Imports {
84
  const python::Import& Import(const std::string& module);
85
  const python::Import& Import(const std::string& module,
86
                               const std::string& name);
87
88
  const python::Import& Export(const std::string& module);
89
  const python::Import& Export(const std::string& module,
90
                               const std::string& name);
91
92
  std::vector<python::Import> imports;
93
  std::vector<python::Import> exports;
94
};
95
}  // namespace python
96
}  // namespace flatbuffers
97
98
#endif  // FLATBUFFERS_INCLUDE_CODEGEN_PYTHON_H_