MCPcopy Create free account
hub / github.com/Nuitka/Nuitka / getModuleVariableReferenceCode

Function getModuleVariableReferenceCode

nuitka/code_generation/VariableCodes.py:98–153  ·  view source on GitHub ↗
(
    to_name, variable_name, use_caching, needs_check, conversion_check, emit, context
)

Source from the content-addressed store, hash-verified

96
97
98def getModuleVariableReferenceCode(
99 to_name, variable_name, use_caching, needs_check, conversion_check, emit, context
100):
101 owner = context.getOwner()
102
103 context.setModuleVariableAccessorCaching(variable_name, use_caching)
104
105 with withObjectCodeTemporaryAssignment2(
106 to_name, "mvar_value", conversion_check, emit, context
107 ) as value_name:
108 emit(
109 "%(value_name)s = %(module_variable_accessor)s(tstate);"
110 % {
111 "value_name": value_name,
112 "module_variable_accessor": getModuleVariableAccessorCodeName(
113 context.getModuleCodeName(), variable_name
114 ),
115 }
116 )
117
118 if needs_check:
119 if (
120 python_version < 0x300
121 and not owner.isCompiledPythonModule()
122 and not owner.isExpressionClassBodyBase()
123 ):
124 error_helper_name = "RAISE_CURRENT_EXCEPTION_GLOBAL_NAME_ERROR"
125 else:
126 error_helper_name = "RAISE_CURRENT_EXCEPTION_NAME_ERROR"
127
128 (
129 exception_state_name,
130 _exception_lineno,
131 ) = context.variable_storage.getExceptionVariableDescriptions()
132
133 emit(
134 """\
135if (unlikely(%(value_name)s == NULL)) {
136 %(error_helper_name)s(tstate, &%(exception_state_name)s, %(var_name)s);
137}
138"""
139 % {
140 "value_name": value_name,
141 "error_helper_name": error_helper_name,
142 "var_name": context.getConstantCode(constant=variable_name),
143 "exception_state_name": exception_state_name,
144 }
145 )
146
147 getErrorExitCode(
148 check_name=value_name,
149 emit=emit,
150 context=context,
151 fetched_exception=True,
152 needs_check=needs_check,
153 )
154
155

Callers 2

Calls 11

getErrorExitCodeFunction · 0.85
emitFunction · 0.50
getOwnerMethod · 0.45
getModuleCodeNameMethod · 0.45
getConstantCodeMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…