Thriftpy / thriftpy2

Pure python approach of Apache Thrift.
MIT License
562 stars 89 forks source link

Add submodule to sys.path when loading child idl file. #249

Closed cocolato closed 4 months ago

cocolato commented 4 months ago

Fixes: https://github.com/Thriftpy/thriftpy2/issues/215

I'm not sure if it's suitable to add the module directly to sys.path, maybe is should implement like this:

for module in thrift.__thrift_meta__["includes"]:
    if module not in sys.modules:
        sys.modules[module.__name__+"_thrift"] = module

then use the import hook to make sure pickle will import the suitable module.

cocolato commented 4 months ago

Now has been updated to a recursive implementation.

aisk commented 4 months ago

I have some concern about whether this code can handle circle including IDLs. Can you add a test case to ensure this?

cocolato commented 4 months ago

Ok, i'll test this part later.

cocolato commented 4 months ago

I have some concern about whether this code can handle circle including IDLs. Can you add a test case to ensure this?

There are already have tests for dead inclusions. https://github.com/Thriftpy/thriftpy2/blob/91b28ea3de4bc3d734364d9e902b8a2ddee5fc80/tests/test_parser.py#L201-L204