{"record":{"id":"df00a55251082c38","repo":"pandas-dev/pandas","slug":"resolver-of-type-name-does-not-implement-the","errorCode":null,"errorMessage":"Resolver of type '{name}' does not implement the __getitem__ method","messagePattern":"Resolver of type '(.+?)' does not implement the __getitem__ method","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"pandas/core/computation/eval.py","lineNumber":107,"sourceCode":"    parser : str\n\n    Raises\n    ------\n    KeyError\n      * If an invalid parser is passed\n    \"\"\"\n    if parser not in PARSERS:\n        raise KeyError(\n            f\"Invalid parser '{parser}' passed, valid parsers are {PARSERS.keys()}\"\n        )\n\n\ndef _check_resolvers(resolvers) -> None:\n    if resolvers is not None:\n        for resolver in resolvers:\n            if not hasattr(resolver, \"__getitem__\"):\n                name = type(resolver).__name__\n                raise TypeError(\n                    f\"Resolver of type '{name}' does not \"\n                    \"implement the __getitem__ method\"\n                )\n\n\ndef _check_expression(expr) -> None:\n    \"\"\"\n    Make sure an expression is not an empty string\n\n    Parameters\n    ----------\n    expr : object\n        An object that can be converted to a string\n\n    Raises\n    ------\n    ValueError\n      * If expr is an empty string","sourceCodeStart":89,"sourceCodeEnd":125,"githubUrl":"https://github.com/pandas-dev/pandas/blob/71959b8cb9b2459c16e14b34f28b178ccfe14735/pandas/core/computation/eval.py#L89-L125","documentation":"Raised by _check_resolvers (pandas/core/computation/eval.py:107) as a TypeError when one of the objects passed in the `resolvers` argument (or a default resolver) does not implement __getitem__. Resolvers are the lookup chain eval/query uses to resolve names in the expression; they must behave like mappings supporting square-bracket access, so a non-subscriptable object is rejected.","triggerScenarios":"`pd.eval('a + b', resolvers=[obj])` where obj lacks __getitem__ (e.g. a list, set, bare object, or a custom class without mapping behavior). Also when a library injects a resolver into the evaluation scope that is not a Mapping.","commonSituations":"Custom resolver classes that forgot to implement __getitem__, passing a list of variables instead of a dict, or integrating eval with a namespace object that is attribute-based rather than item-based.","solutions":["Pass a Mapping-like resolver (dict or collections.abc.Mapping subclass) that supports `resolver[name]`.","Wrap attribute-based namespaces: build a dict `{k: getattr(obj,k) for k in dir(obj)}` and pass that.","Implement __getitem__ on your custom resolver class."],"exampleFix":"# before\npd.eval('a + b', resolvers=[my_object])  # no __getitem__\n\n# after\nns = {'a': my_object.a, 'b': my_object.b}\npd.eval('a + b', resolvers=[ns])","handlingStrategy":"type-guard","validationCode":"def validate_resolvers(resolvers):\n    for r in (resolvers or []):\n        if not hasattr(r, '__getitem__'):\n            raise TypeError(f\"Resolver {type(r).__name__} must implement __getitem__\")\n    return resolvers","typeGuard":"def is_valid_resolver(resolver) -> bool:\n    return hasattr(resolver, '__getitem__')","tryCatchPattern":"try:\n    result = pd.eval('a + b', resolvers=resolvers)\nexcept TypeError as e:\n    if 'does not implement the __getitem__' in str(e):\n        resolvers = [r if hasattr(r, '__getitem__') else vars(r) for r in resolvers]\n        result = pd.eval('a + b', resolvers=resolvers)\n    else:\n        raise","preventionTips":["Pass dict or Mapping subclasses as resolvers.","Implement __getitem__ on custom namespace classes.","Convert attribute namespaces to dicts with vars() or a comprehension."],"tags":["eval","resolver","getitem","mapping","typeerror"],"analyzedSha":"71959b8cb9b2459c16e14b34f28b178ccfe14735","analyzedAt":"2026-08-07T01:30:20.476Z","schemaVersion":2},"datasetVersion":"2026-08-07T03:17:09.362Z"}