Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #41 #42

Merged
merged 3 commits into from
Feb 23, 2019
Merged
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,4 @@ pip-log.txt
*.sublime-workspace
*.sw[op]
env/
.vscode/
9 changes: 4 additions & 5 deletions tests/container.thrift
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
struct ListStruct {
1: optional list<ListItem> list_items,
}

struct ListItem {
1: optional list<string> list_string,
2: optional list<list<string>> list_list_string,
Expand All @@ -12,8 +16,3 @@ struct MixItem {
1: optional list<map<string, string>> list_map,
2: optional map<string, list<string>> map_list,
}


struct ListStruct {
1: optional list<ListItem> list_items,
}
13 changes: 9 additions & 4 deletions thriftpy2/parser/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ def fill_incomplete_ttype(tmodule, definition):
if isinstance(definition, tuple):
# fill const value
if definition[0] == 'UNKNOWN_CONST':
ttype = get_definition(tmodule, incomplete_type[definition[1]][0], definition[3])
ttype = get_definition(
tmodule, incomplete_type[definition[1]][0], definition[3])
return _cast(ttype)(definition[2])
# fill an incomplete alias ttype
if definition[1] in incomplete_type:
Expand All @@ -61,7 +62,7 @@ def fill_incomplete_ttype(tmodule, definition):
for name, attr in definition.__dict__.items():
if name.startswith('__'): # skip inner attribute
continue
setattr(definition, name, fill_incomplete_ttype(tmodule, attr))
setattr(definition, name, fill_incomplete_ttype(definition, attr))
# handle struct ttype
elif isinstance(definition, TPayloadMeta):
for index, value in definition.thrift_spec.items():
Expand All @@ -88,11 +89,15 @@ def fill_incomplete_ttype(tmodule, definition):
),
) + tuple(value[1:])
# if the ttype which field's ttype contains is incomplete
elif isinstance(value[2], tuple):
elif value[2] in incomplete_type:
definition.thrift_spec[index] = (
value[0],
value[1],
fill_incomplete_ttype(tmodule, value[2]),
fill_incomplete_ttype(
tmodule, get_definition(
tmodule, *incomplete_type[value[2]]
)
),
value[3])
# handle service method
elif hasattr(definition, "thrift_services"):
Expand Down