Analyze single top-level function or method. Process the body of the function (including nested functions) again and again, until all names have been resolved (or iteration limit reached).
(
analyzer: SemanticAnalyzer,
state: State,
module: str,
target: str,
node: FuncDef | OverloadedFuncDef | Decorator,
active_type: TypeInfo | None,
patches: Patches,
)
| 278 | |
| 279 | |
| 280 | def process_top_level_function( |
| 281 | analyzer: SemanticAnalyzer, |
| 282 | state: State, |
| 283 | module: str, |
| 284 | target: str, |
| 285 | node: FuncDef | OverloadedFuncDef | Decorator, |
| 286 | active_type: TypeInfo | None, |
| 287 | patches: Patches, |
| 288 | ) -> None: |
| 289 | """Analyze single top-level function or method. |
| 290 | |
| 291 | Process the body of the function (including nested functions) again and again, |
| 292 | until all names have been resolved (or iteration limit reached). |
| 293 | """ |
| 294 | # We need one more iteration after incomplete is False (e.g. to report errors, if any). |
| 295 | final_iteration = False |
| 296 | incomplete = True |
| 297 | # Start in the incomplete state (no missing names will be reported on first pass). |
| 298 | # Note that we use module name, since functions don't create qualified names. |
| 299 | deferred = [module] |
| 300 | analyzer.deferral_debug_context.clear() |
| 301 | analyzer.incomplete_namespaces.add(module) |
| 302 | iteration = 0 |
| 303 | while deferred: |
| 304 | iteration += 1 |
| 305 | if iteration == MAX_ITERATIONS: |
| 306 | # Just pick some module inside the current SCC for error context. |
| 307 | assert state.tree is not None |
| 308 | with analyzer.file_context(state.tree, state.options): |
| 309 | analyzer.report_hang() |
| 310 | break |
| 311 | if not (deferred or incomplete) or final_iteration: |
| 312 | # OK, this is one last pass, now missing names will be reported. |
| 313 | analyzer.incomplete_namespaces.discard(module) |
| 314 | deferred, incomplete, progress = semantic_analyze_target( |
| 315 | target, module, state, node, active_type, final_iteration, patches |
| 316 | ) |
| 317 | if not incomplete: |
| 318 | state.manager.incomplete_namespaces.discard(module) |
| 319 | if final_iteration: |
| 320 | assert not deferred, "Must not defer during final iteration" |
| 321 | if not progress: |
| 322 | final_iteration = True |
| 323 | |
| 324 | analyzer.incomplete_namespaces.discard(module) |
| 325 | # After semantic analysis is done, discard local namespaces |
| 326 | # to avoid memory hoarding. |
| 327 | analyzer.saved_locals.clear() |
| 328 | |
| 329 | |
| 330 | TargetInfo: _TypeAlias = tuple[ |
no test coverage detected
searching dependent graphs…