{"record":{"id":"441ac0f9d74131b9","repo":"nodejs/node","slug":"either-extensions-or-filter-func-can-be-passed-bu","errorCode":null,"errorMessage":"either extensions or filter_func can be passed, but not both","messagePattern":"either extensions or filter_func can be passed, but not both","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"tools/inspector_protocol/jinja2/environment.py","lineNumber":752,"sourceCode":"        \"\"\"Returns a list of templates for this environment.  This requires\n        that the loader supports the loader's\n        :meth:`~BaseLoader.list_templates` method.\n\n        If there are other files in the template folder besides the\n        actual templates, the returned list can be filtered.  There are two\n        ways: either `extensions` is set to a list of file extensions for\n        templates, or a `filter_func` can be provided which is a callable that\n        is passed a template name and should return `True` if it should end up\n        in the result list.\n\n        If the loader does not support that, a :exc:`TypeError` is raised.\n\n        .. versionadded:: 2.4\n        \"\"\"\n        x = self.loader.list_templates()\n        if extensions is not None:\n            if filter_func is not None:\n                raise TypeError('either extensions or filter_func '\n                                'can be passed, but not both')\n            filter_func = lambda x: '.' in x and \\\n                                    x.rsplit('.', 1)[1] in extensions\n        if filter_func is not None:\n            x = list(ifilter(filter_func, x))\n        return x\n\n    def handle_exception(self, exc_info=None, rendered=False, source_hint=None):\n        \"\"\"Exception handling helper.  This is used internally to either raise\n        rewritten exceptions or return a rendered traceback for the template.\n        \"\"\"\n        global _make_traceback\n        if exc_info is None:\n            exc_info = sys.exc_info()\n\n        # the debugging module is imported when it's used for the first time.\n        # we're doing a lot of stuff there and for applications that do not\n        # get any exceptions in template rendering there is no need to load","sourceCodeStart":734,"sourceCodeEnd":770,"githubUrl":"https://github.com/nodejs/node/blob/1b2de5e052fc0fb95fd7fb6846dcec4ade598e9e/tools/inspector_protocol/jinja2/environment.py#L734-L770","documentation":"Raised by Environment.list_templates (jinja2 environment.py) when both `extensions` and `filter_func` keyword arguments are supplied. The method supports filtering template names by either a list of file extensions or a custom predicate function, but not both simultaneously — supplying both is an ambiguous request and is rejected.","triggerScenarios":"Calling `env.list_templates(extensions=['html'], filter_func=my_fn)`; wrapping list_templates and forwarding both optional kwargs when both happen to be set.","commonSituations":"Helper functions that expose both options and pass them straight through; configuration-driven code that builds kwargs from settings and ends up populating both.","solutions":["Pass only one of the two; if you need both constraints, fold them into a single filter_func.","In wrapper code, assert/branch on which kwarg is set before forwarding.","Combine: `filter_func = lambda name: name.endswith('.html') and my_fn(name)`."],"exampleFix":"# before\nenv.list_templates(extensions=['html'], filter_func=custom)\n# after\nenv.list_templates(filter_func=lambda n: n.endswith('.html') and custom(n))","handlingStrategy":"validation","validationCode":"def list_templates(env, extensions=None, filter_func=None):\n    if extensions is not None and filter_func is not None:\n        if extensions:\n            exts = set(extensions)\n            filter_func = (lambda f: (lambda n: n.rsplit('.',1)[-1] in exts and f(n)))(filter_func)\n        extensions = None\n    return env.list_templates(extensions=extensions, filter_func=filter_func)","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Pass only one of extensions / filter_func to list_templates.","In wrappers, branch on which kwarg is set before forwarding.","Combine constraints into a single filter_func when both are needed."],"tags":["jinja2","list-templates","api","validation"],"backgroundTag":null,"analyzedSha":"1b2de5e052fc0fb95fd7fb6846dcec4ade598e9e","analyzedAt":"2026-08-13T00:53:24.642Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}