14
14
import types
15
15
16
16
from .parser import parse , parse_fp , threadlocal , _cast
17
- from .exc import ThriftParserError
17
+ from .exc import ThriftParserError , ThriftModuleNameConflict
18
18
from ..thrift import TPayloadMeta
19
19
20
20
@@ -41,12 +41,21 @@ def load(path,
41
41
# add sub modules to sys.modules recursively
42
42
if real_module :
43
43
sys .modules [module_name ] = thrift
44
- sub_modules = thrift .__thrift_meta__ ["includes" ][:]
45
- while sub_modules :
46
- module = sub_modules .pop ()
47
- if module not in sys .modules :
48
- sys .modules [module .__name__ ] = module
49
- sub_modules .extend (module .__thrift_meta__ ["includes" ])
44
+ include_thrifts = thrift .__thrift_meta__ ["includes" ][:]
45
+ while include_thrifts :
46
+ include_thrift = include_thrifts .pop ()
47
+ registered_thrift = sys .modules .get (include_thrift .__thrift_module_name__ )
48
+ if registered_thrift is None :
49
+ sys .modules [include_thrift .__thrift_module_name__ ] = include_thrift
50
+ if hasattr (include_thrift , "__thrift_meta__" ):
51
+ include_thrifts .extend (
52
+ include_thrift .__thrift_meta__ ["includes" ][:])
53
+ else :
54
+ if registered_thrift .__thrift_file__ != include_thrift .__thrift_file__ :
55
+ raise ThriftModuleNameConflict (
56
+ 'Module name conflict between "%s" and "%s"' %
57
+ (registered_thrift .__thrift_file__ , include_thrift .__thrift_file__ )
58
+ )
50
59
return thrift
51
60
52
61
0 commit comments