{"record":{"id":"9903045c80d2bc73","repo":"facebookresearch/detectron2","slug":"target-of-lazycall-must-be-a-callable-or-defines-a","errorCode":null,"errorMessage":"target of LazyCall must be a callable or defines a callable! Got {target}","messagePattern":"target of LazyCall must be a callable or defines a callable! Got (.+?)","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"detectron2/config/lazy.py","lineNumber":44,"sourceCode":"    \"\"\"\n    Wrap a callable so that when it's called, the call will not be executed,\n    but returns a dict that describes the call.\n\n    LazyCall object has to be called with only keyword arguments. Positional\n    arguments are not yet supported.\n\n    Examples:\n    ::\n        from detectron2.config import instantiate, LazyCall\n\n        layer_cfg = LazyCall(nn.Conv2d)(in_channels=32, out_channels=32)\n        layer_cfg.out_channels = 64   # can edit it afterwards\n        layer = instantiate(layer_cfg)\n    \"\"\"\n\n    def __init__(self, target):\n        if not (callable(target) or isinstance(target, (str, abc.Mapping))):\n            raise TypeError(\n                f\"target of LazyCall must be a callable or defines a callable! Got {target}\"\n            )\n        self._target = target\n\n    def __call__(self, **kwargs):\n        if is_dataclass(self._target):\n            # omegaconf object cannot hold dataclass type\n            # https://github.com/omry/omegaconf/issues/784\n            target = _convert_target_to_string(self._target)\n        else:\n            target = self._target\n        kwargs[\"_target_\"] = target\n\n        return DictConfig(content=kwargs, flags={\"allow_objects\": True})\n\n\ndef _visit_dict_config(cfg, func):\n    \"\"\"","sourceCodeStart":26,"sourceCodeEnd":62,"githubUrl":"https://github.com/facebookresearch/detectron2/blob/a2f4a8771ab77e8411c26b27f24f9489a28a2453/detectron2/config/lazy.py#L26-L62","documentation":"LazyCall wraps a target that must be a callable (class/function), a string (dotted import path), or a Mapping defining a 'target'. Passing anything else (int, None, list, already-instantiated object) is rejected at construction time.","triggerScenarios":"LazyCall(64), LazyCall(None), LazyCall([nn.Conv2d]), or LazyCall(some_instance) where the instance is neither callable nor a Mapping with a callable 'target'.","commonSituations":"Confusing LazyCall with instantiate and passing a config value or a fully constructed module; typos where a variable holding a class is actually a number/string without a dotted path.","solutions":["Pass the callable itself: LazyCall(nn.Conv2d)","Or pass a dotted string path: LazyCall(\"torch.nn.Conv2d\")","Or pass a mapping like {'target': 'torch.nn.Conv2d', 'args': [3, 64]}"],"exampleFix":"# before\ncfg = LazyCall(model.backbone)  # model.backbone is an int like 50\ncfg = LazyCall(50)\n# after\ncfg = LazyCall(\"detectron2.modeling.backbone.ResNet\")\ncfg.depth = 50","handlingStrategy":"type-guard","validationCode":"assert callable(target) or isinstance(target, (str, dict)), f\"invalid LazyCall target: {target!r}\"","typeGuard":"def is_valid_lazy_target(t) -> bool:\n    return callable(t) or isinstance(t, str) or (isinstance(t, dict) and (\"target\" in t))","tryCatchPattern":null,"preventionTips":["Pass classes/functions or dotted-path strings to LazyCall","Never pass primitive values or constructed objects as target","Unit-test config construction paths that build LazyCall targets"],"tags":["lazy-config","detectron2","type-error","instantiation"],"backgroundTag":"invalid-lazy-call-target","analyzedSha":"a2f4a8771ab77e8411c26b27f24f9489a28a2453","analyzedAt":"2026-08-27T12:08:21.260Z","schemaVersion":2},"datasetVersion":"2026-08-27T13:17:12.746Z"}