Skip to content

Commit c186291

Browse files
committed
Make RenderTypeType private
1 parent ceb14cf commit c186291

2 files changed

Lines changed: 4 additions & 73 deletions

File tree

Cargo.lock

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

build.rs

Lines changed: 2 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -383,7 +383,6 @@ impl PythonBindGenerator {
383383
self.write_str("}");
384384
self.write_str("");
385385

386-
self.write_str("#[pyclass(module = \"rlbot_flatbuffers\")]");
387386
self.write_str("#[derive(Debug, Default, Clone, Copy)]");
388387
self.write_string(format!("pub enum {}Type {{", self.struct_name));
389388
self.write_str(" #[default]");
@@ -392,7 +391,6 @@ impl PythonBindGenerator {
392391
let variable_name = &variable_info[0];
393392

394393
if variable_name == "NONE" {
395-
self.file_contents.push(Cow::Borrowed(" #[pyo3(name = \"NONE\")]"));
396394
self.file_contents.push(Cow::Borrowed(" None,"));
397395
} else {
398396
self.file_contents.push(Cow::Owned(format!(" {variable_name},")));
@@ -401,15 +399,10 @@ impl PythonBindGenerator {
401399

402400
self.write_str("}");
403401
self.write_str("");
404-
405-
self.generate_union_py_methods();
406-
407402
self.write_str("#[pyclass(module = \"rlbot_flatbuffers\")]");
408403
self.write_str("#[derive(Debug, Default, Clone)]");
409404
self.write_string(format!("pub struct {} {{", self.struct_name));
410-
411-
self.write_str(" #[pyo3(get)]");
412-
self.write_string(format!(" pub item_type: {}Type,", self.struct_name));
405+
self.write_string(format!(" item_type: {}Type,", self.struct_name));
413406

414407
for variable_info in &self.types {
415408
let variable_type = &variable_info[1];
@@ -421,53 +414,14 @@ impl PythonBindGenerator {
421414
let snake_case_name = &variable_info[2];
422415

423416
self.file_contents.push(Cow::Owned(format!(
424-
" pub {snake_case_name}: Option<Py<super::{variable_type}>>,",
417+
" {snake_case_name}: Option<Py<super::{variable_type}>>,",
425418
)));
426419
}
427420

428421
self.write_str("}");
429422
self.write_str("");
430423
}
431424

432-
fn generate_union_py_methods(&mut self) {
433-
self.write_str("#[pymethods]");
434-
self.write_string(format!("impl {}Type {{", self.struct_name));
435-
436-
self.write_str(" #[new]");
437-
assert!(u8::try_from(self.types.len()).is_ok());
438-
439-
self.write_str(" #[pyo3(signature = (value=Default::default()))]");
440-
self.write_str(" pub fn new(value: u8) -> Self {");
441-
self.write_str(" match value {");
442-
443-
for (i, variable_info) in self.types.iter().enumerate() {
444-
let mut variable_name = variable_info[0].as_str();
445-
446-
if variable_name == "NONE" {
447-
variable_name = "None";
448-
}
449-
450-
self.file_contents
451-
.push(Cow::Owned(format!(" {i} => Self::{variable_name},")));
452-
}
453-
454-
if self.types.len() != usize::from(u8::MAX) {
455-
self.write_str(" v => panic!(\"Unknown value: {v}\"),");
456-
}
457-
458-
self.write_str(" }");
459-
self.write_str(" }");
460-
self.write_str("");
461-
462-
self.generate_str_method();
463-
464-
self.write_str("");
465-
466-
self.generate_enum_repr_method();
467-
468-
self.write_str("}");
469-
}
470-
471425
fn generate_from_flat_impls(&mut self) {
472426
match self.bind_type {
473427
PythonBindType::Enum => self.generate_enum_from_flat_impls(),
@@ -1445,32 +1399,9 @@ fn pyi_generator(type_data: &[(String, String, Vec<Vec<String>>)]) -> io::Result
14451399

14461400
let is_union = !types.is_empty() && types[0][1].is_empty();
14471401

1448-
if is_union {
1449-
file_contents.push(Cow::Owned(format!("class {type_name}Type:")));
1450-
1451-
for (i, variable_info) in types.iter().enumerate() {
1452-
let variable_name = variable_info[0].as_str();
1453-
file_contents.push(Cow::Owned(format!(" {variable_name} = {type_name}Type({i})")));
1454-
}
1455-
1456-
file_contents.push(Cow::Borrowed(""));
1457-
1458-
file_contents.push(Cow::Borrowed(" def __init__(self, value: int = 0): ..."));
1459-
file_contents.push(Cow::Borrowed(" def __str__(self) -> str: ..."));
1460-
file_contents.push(Cow::Borrowed(" def __repr__(self) -> str: ..."));
1461-
file_contents.push(Cow::Borrowed(" def __int__(self) -> int: ..."));
1462-
file_contents.push(Cow::Owned(format!(
1463-
" def __richcmp__(self, other: {type_name}, op: int) -> bool: ..."
1464-
)));
1465-
1466-
file_contents.push(Cow::Borrowed(""));
1467-
}
1468-
14691402
file_contents.push(Cow::Owned(format!("class {type_name}:")));
14701403

14711404
if is_union {
1472-
file_contents.push(Cow::Owned(format!(" item_type: {type_name}Type")));
1473-
14741405
let types = types
14751406
.iter()
14761407
.map(|variable_info| variable_info[0].as_str())

0 commit comments

Comments
 (0)