Skip to content

Conversation

@truebit
Copy link
Contributor

@truebit truebit commented Apr 22, 2025

add namespace attributes to __thrift_meta__, so we could access namespace info. support #294

thrift = load("some.thrift")
namespaces = thrift.__thrift_meta__['namespaces']
cpp_namespace = namespaces.get('cpp')  # get ns by cpp lang
java_namespace = namespaces.get('java')  # get ns by java lang

@truebit truebit changed the title support #294 add namespace attributes to __thrift_meta__, then we could access namespace info. Apr 22, 2025
Comment on lines +93 to +109
thrift = threadlocal.thrift_stack[-1]
scope = p[2] # language identifier, e.g. 'py', 'java', 'cpp'
namespace = p[3] # namespace value, e.g. 'tutorial', 'shared'

# Initialize __thrift_meta__ if not exists
if not hasattr(thrift, '__thrift_meta__'):
meta = collections.defaultdict(list)
setattr(thrift, '__thrift_meta__', meta)
else:
meta = getattr(thrift, '__thrift_meta__')

# Initialize 'namespaces' as dict if not exists
if 'namespaces' not in meta:
meta['namespaces'] = {}

# Store namespace information
meta['namespaces'][scope] = namespace
Copy link
Collaborator

@cocolato cocolato Apr 24, 2025

Choose a reason for hiding this comment

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

Suggested change
thrift = threadlocal.thrift_stack[-1]
scope = p[2] # language identifier, e.g. 'py', 'java', 'cpp'
namespace = p[3] # namespace value, e.g. 'tutorial', 'shared'
# Initialize __thrift_meta__ if not exists
if not hasattr(thrift, '__thrift_meta__'):
meta = collections.defaultdict(list)
setattr(thrift, '__thrift_meta__', meta)
else:
meta = getattr(thrift, '__thrift_meta__')
# Initialize 'namespaces' as dict if not exists
if 'namespaces' not in meta:
meta['namespaces'] = {}
# Store namespace information
meta['namespaces'][scope] = namespace
_add_thrift_meta("namespaces", (p[2], p[3]))

namespaces metainfo should not be a one - way map. Implementing it in this way would be more reasonable.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants