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

Function prepare_fast_path

mypyc/irbuild/prepare.py:303–330  ·  view source on GitHub ↗

Add fast (direct) variants of methods in non-extension classes.

(
    ir: ClassIR,
    module_name: str,
    cdef: ClassDef,
    mapper: Mapper,
    node: SymbolNode | None,
    options: CompilerOptions,
)

Source from the content-addressed store, hash-verified

301
302
303def prepare_fast_path(
304 ir: ClassIR,
305 module_name: str,
306 cdef: ClassDef,
307 mapper: Mapper,
308 node: SymbolNode | None,
309 options: CompilerOptions,
310) -> None:
311 """Add fast (direct) variants of methods in non-extension classes."""
312 if ir.is_enum:
313 # We check that non-empty enums are implicitly final in mypy, so we
314 # can generate direct calls to enum methods.
315 if isinstance(node, OverloadedFuncDef):
316 if node.is_property:
317 return
318 node = node.impl
319 if not isinstance(node, FuncDef):
320 # TODO: support decorated methods (at least @classmethod and @staticmethod).
321 return
322 # The simplest case is a regular or overloaded method without decorators. In this
323 # case we can generate practically identical IR method body, but with a signature
324 # suitable for direct calls (usual non-extension class methods are converted to
325 # callable classes, and thus have an extra __mypyc_self__ argument).
326 name = FAST_PREFIX + node.name
327 sig = mapper.fdef_to_sig(node, options.strict_dunders_typing)
328 decl = FuncDecl(name, cdef.name, module_name, sig, FUNC_NORMAL)
329 ir.method_decls[name] = decl
330 return
331
332
333def is_valid_multipart_property_def(prop: OverloadedFuncDef) -> bool:

Callers 1

Calls 3

FuncDeclClass · 0.90
isinstanceFunction · 0.85
fdef_to_sigMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…