@@ -48,12 +48,22 @@ typedef std::set<ImportMapEntry> ImportMap;
4848static const CommentConfig def_comment = {nullptr , " #" , nullptr };
4949static const std::string Indent = " " ;
5050
51+ inline Namer::Config PythonNamerConfig (const Namer::Config& input,
52+ const IDLOptions& opts,
53+ const std::string& path) {
54+ auto cfg = WithFlagOptions (input, opts, path);
55+ if (opts.python_fields_snake_case ) {
56+ cfg.fields = Case::kSnake ;
57+ }
58+ return cfg;
59+ }
60+
5161class PythonStubGenerator {
5262 public:
5363 PythonStubGenerator (const Parser& parser, const std::string& path,
5464 const Version& version)
5565 : parser_{parser},
56- namer_{WithFlagOptions (kStubConfig , parser.opts , path),
66+ namer_{PythonNamerConfig (kStubConfig , parser.opts , path),
5767 Keywords (version)},
5868 version_ (version) {}
5969
@@ -698,7 +708,7 @@ class PythonGenerator : public BaseGenerator {
698708 : BaseGenerator(parser, path, file_name, " " /* not used */ ,
699709 " " /* not used */ , " py" ),
700710 float_const_gen_ (" float('nan')" , " float('inf')" , " float('-inf')" ),
701- namer_(WithFlagOptions (kConfig , parser.opts, path), Keywords(version)) {
711+ namer_(PythonNamerConfig (kConfig , parser.opts, path), Keywords(version)) {
702712 }
703713
704714 // Most field accessors need to retrieve and test the field offset first,
@@ -1321,7 +1331,7 @@ class PythonGenerator : public BaseGenerator {
13211331 } else {
13221332 code += IsArray (field_type) ? " " : " " ;
13231333 code += indent + " builder.Prepend" + GenMethod (field) + " (" ;
1324- code += nameprefix + namer_.Variable (field);
1334+ code += nameprefix + namer_.Field (field);
13251335 size_t array_cnt = index + (IsArray (field_type) ? 1 : 0 );
13261336 for (size_t i = 0 ; in_array && i < array_cnt; i++) {
13271337 code += " [_idx" + NumToString (i) + " -1]" ;
0 commit comments