MCPcopy Index your code
hub / github.com/python/mypy / get_module_group_prefix

Method get_module_group_prefix

mypyc/codegen/emit.py:298–322  ·  view source on GitHub ↗

Get the group prefix for a module (relative to the current group). The prefix should be prepended to the object name whenever accessing an object from this module. If the module lives is in the current compilation group, there is no prefix. But if it lives in a dif

(self, module_name: str)

Source from the content-addressed store, hash-verified

296 return "__LL%d" % self.context.temp_counter
297
298 def get_module_group_prefix(self, module_name: str) -> str:
299 """Get the group prefix for a module (relative to the current group).
300
301 The prefix should be prepended to the object name whenever
302 accessing an object from this module.
303
304 If the module lives is in the current compilation group, there is
305 no prefix. But if it lives in a different group (and hence a separate
306 extension module), we need to access objects from it indirectly via an
307 export table.
308
309 For example, for code in group `a` to call a function `bar` in group `b`,
310 it would need to do `exports_b.CPyDef_bar(...)`, while code that is
311 also in group `b` can simply do `CPyDef_bar(...)`.
312
313 Thus the prefix for a module in group `b` is 'exports_b.' if the current
314 group is *not* b and just '' if it is.
315 """
316 groups = self.context.group_map
317 target_group_name = groups.get(module_name)
318 if target_group_name and target_group_name != self.context.group_name:
319 self.context.group_deps.add(target_group_name)
320 return f"exports_{exported_name(target_group_name)}."
321 else:
322 return ""
323
324 def get_group_prefix(self, obj: ClassIR | FuncDecl) -> str:
325 """Get the group prefix for an object."""

Callers 2

get_group_prefixMethod · 0.95
static_nameMethod · 0.95

Calls 3

exported_nameFunction · 0.90
getMethod · 0.45
addMethod · 0.45

Tested by

no test coverage detected