Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/idl_gen_python.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2026,7 +2026,7 @@ class PythonGenerator : public BaseGenerator {
const auto field_method = namer_.Method(field);
const auto struct_var = namer_.Variable(struct_def);
const EnumDef& enum_def = *field.value.type.enum_def;
auto union_type = namer_.Type(enum_def);
auto union_type = namer_.Function(enum_def);

if (parser_.opts.include_dependence_headers) {
union_type = namer_.NamespacedType(enum_def) + "." + union_type;
Expand Down
4 changes: 2 additions & 2 deletions tests/MyGame/Example/NestedUnion/NestedUnionTest.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ def NestedUnionTestEnd(builder: flatbuffers.Builder) -> int:
def End(builder: flatbuffers.Builder) -> int:
return NestedUnionTestEnd(builder)

import MyGame.Example.NestedUnion.Any
import MyGame.Example.NestedUnion.Any_Data
import MyGame.Example.NestedUnion.TestSimpleTableWithEnum
import MyGame.Example.NestedUnion.Vec3
try:
Expand Down Expand Up @@ -141,7 +141,7 @@ def _UnPack(self, nestedUnionTest):
if self.name is not None:
self.name = self.name.decode('utf-8')
self.dataType = nestedUnionTest.DataType()
self.data = MyGame.Example.NestedUnion.Any.AnyCreator(self.dataType, nestedUnionTest.Data())
self.data = MyGame.Example.NestedUnion.Any_Data.AnyDataCreator(self.dataType, nestedUnionTest.Data())
self.id = nestedUnionTest.Id()

# NestedUnionTestT
Expand Down
10 changes: 5 additions & 5 deletions tests/MyGame/Example/NestedUnion/NestedUnionTest.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import flatbuffers
import numpy as np

import typing
from MyGame.Example.NestedUnion.Any import Any
from MyGame.Example.NestedUnion.Any_Data import Any_Data
from MyGame.Example.NestedUnion.TestSimpleTableWithEnum import TestSimpleTableWithEnumT
from MyGame.Example.NestedUnion.Vec3 import Vec3T
from flatbuffers import table
Expand All @@ -18,18 +18,18 @@ class NestedUnionTest(object):
def GetRootAsNestedUnionTest(cls, buf: bytes, offset: int) -> NestedUnionTest: ...
def Init(self, buf: bytes, pos: int) -> None: ...
def Name(self) -> str | None: ...
def DataType(self) -> typing.Literal[Any.NONE, Any.Vec3, Any.TestSimpleTableWithEnum]: ...
def DataType(self) -> typing.Literal[Any_Data.NONE, Any_Data.Vec3, Any_Data.TestSimpleTableWithEnum]: ...
def Data(self) -> table.Table | None: ...
def Id(self) -> int: ...
class NestedUnionTestT(object):
name: str | None
dataType: typing.Literal[Any.NONE, Any.Vec3, Any.TestSimpleTableWithEnum]
dataType: typing.Literal[Any_Data.NONE, Any_Data.Vec3, Any_Data.TestSimpleTableWithEnum]
data: typing.Union[None, Vec3T, TestSimpleTableWithEnumT]
id: int
def __init__(
self,
name: str | None = ...,
dataType: typing.Literal[Any.NONE, Any.Vec3, Any.TestSimpleTableWithEnum] = ...,
dataType: typing.Literal[Any_Data.NONE, Any_Data.Vec3, Any_Data.TestSimpleTableWithEnum] = ...,
data: typing.Union[None, Vec3T, TestSimpleTableWithEnumT] = ...,
id: int = ...,
) -> None: ...
Expand All @@ -44,7 +44,7 @@ class NestedUnionTestT(object):
def NestedUnionTestStart(builder: flatbuffers.Builder) -> None: ...
def Start(builder: flatbuffers.Builder) -> None: ...
def NestedUnionTestAddName(builder: flatbuffers.Builder, name: uoffset) -> None: ...
def NestedUnionTestAddDataType(builder: flatbuffers.Builder, dataType: typing.Literal[Any.NONE, Any.Vec3, Any.TestSimpleTableWithEnum]) -> None: ...
def NestedUnionTestAddDataType(builder: flatbuffers.Builder, dataType: typing.Literal[Any_Data.NONE, Any_Data.Vec3, Any_Data.TestSimpleTableWithEnum]) -> None: ...
def NestedUnionTestAddData(builder: flatbuffers.Builder, data: uoffset) -> None: ...
def NestedUnionTestAddId(builder: flatbuffers.Builder, id: int) -> None: ...
def NestedUnionTestEnd(builder: flatbuffers.Builder) -> uoffset: ...
Expand Down
4 changes: 2 additions & 2 deletions tests/nested_union_test.fbs
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ table Vec3 {
test3:Test;
}

union Any { Vec3, TestSimpleTableWithEnum }
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is going to change this tests generated code for all languages.. lets not do that.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, what would you suggest as an alternative?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the least intrusive solution is to create a dedicated test file and case for this

union Any_Data { Vec3, TestSimpleTableWithEnum }

table NestedUnionTest {
name:string;
data:Any;
data:Any_Data;
id:short;
}

Expand Down
Loading