Coverage Report

Created: 2026-04-12 06:27

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
    /*keywords_casing=*/Namer::Config::KeywordsCasing::CaseSensitive,
30
    /*filenames=*/Case::kKeep,
31
    /*directories=*/Case::kKeep,
32
    /*output_path=*/"",
33
    /*filename_suffix=*/"",
34
    /*filename_extension=*/".py",
35
};
36
37
static const Namer::Config kStubConfig = {
38
    /*types=*/Case::kKeep,
39
    /*constants=*/Case::kScreamingSnake,
40
    /*methods=*/Case::kUpperCamel,
41
    /*functions=*/Case::kUpperCamel,
42
    /*fields=*/Case::kLowerCamel,
43
    /*variables=*/Case::kLowerCamel,
44
    /*variants=*/Case::kKeep,
45
    /*enum_variant_seperator=*/".",
46
    /*escape_keywords=*/Namer::Config::Escape::AfterConvertingCase,
47
    /*namespaces=*/Case::kKeep,  // Packages in python.
48
    /*namespace_seperator=*/".",
49
    /*object_prefix=*/"",
50
    /*object_suffix=*/"T",
51
    /*keyword_prefix=*/"",
52
    /*keyword_suffix=*/"_",
53
    /*keywords_casing=*/Namer::Config::KeywordsCasing::CaseSensitive,
54
    /*filenames=*/Case::kKeep,
55
    /*directories=*/Case::kKeep,
56
    /*output_path=*/"",
57
    /*filename_suffix=*/"",
58
    /*filename_extension=*/".pyi",
59
};
60
61
// `Version` represent a Python version.
62
//
63
// The zero value (i.e. `Version{}`) represents both Python2 and Python3.
64
//
65
// https://docs.python.org/3/faq/general.html#how-does-the-python-version-numbering-scheme-work
66
struct Version {
67
  explicit Version(const std::string& version);
68
69
  bool IsValid() const;
70
71
  int16_t major = 0;
72
  int16_t minor = 0;
73
  int16_t micro = 0;
74
};
75
76
std::set<std::string> Keywords(const Version& version);
77
78
struct Import {
79
0
  bool IsLocal() const { return module == "."; }
80
81
  std::string module;
82
  std::string name;
83
};
84
85
struct Imports {
86
  const python::Import& Import(const std::string& module);
87
  const python::Import& Import(const std::string& module,
88
                               const std::string& name);
89
90
  const python::Import& Export(const std::string& module);
91
  const python::Import& Export(const std::string& module,
92
                               const std::string& name);
93
94
  std::vector<python::Import> imports;
95
  std::vector<python::Import> exports;
96
};
97
}  // namespace python
98
}  // namespace flatbuffers
99
100
#endif  // FLATBUFFERS_INCLUDE_CODEGEN_PYTHON_H_