{"record":{"id":"7ad8efc81e94cb16","repo":"pola-rs/polars","slug":"self-module-name-r-object-has-no-attribute-name-r","errorCode":null,"errorMessage":"{self._module_name!r} object has no attribute {name!r}","messagePattern":"(.+?) object has no attribute (.+?)","errorType":"exception","errorClass":"AttributeError","httpStatus":null,"severity":"info","filePath":"py-polars/src/polars/_dependencies.py","lineNumber":85,"sourceCode":"        \"\"\"\n        self._module_available = module_available\n        self._module_name = module_name\n        self._globals = globals()\n        super().__init__(module_name)\n\n    def _import(self) -> ModuleType:\n        # import the referenced module, replacing the proxy in this module's globals\n        module = import_module(self.__name__)\n        self._globals[self._module_name] = module\n        self.__dict__.update(module.__dict__)\n        return module\n\n    def __getattr__(self, name: str) -> Any:\n        # have \"hasattr('__wrapped__')\" return False without triggering import\n        # (it's for decorators, not modules, but keeps \"make doctest\" happy)\n        if name == \"__wrapped__\":\n            msg = f\"{self._module_name!r} object has no attribute {name!r}\"\n            raise AttributeError(msg)\n\n        # accessing the proxy module's attributes triggers import of the real thing\n        if self._module_available:\n            # import the module and return the requested attribute\n            module = self._import()\n            return getattr(module, name)\n\n        # user has not installed the proxied/lazy module\n        elif name == \"__name__\":\n            return self._module_name\n        elif re.match(r\"^__\\w+__$\", name) and name != \"__version__\":\n            # allow some minimal introspection on private module\n            # attrs to avoid unnecessary error-handling elsewhere\n            return None\n        else:\n            # all other attribute access raises a helpful exception\n            pfx = self._mod_pfx.get(self._module_name, \"\")\n            msg = f\"{pfx}{name} requires {self._module_name!r} module to be installed\"","sourceCodeStart":67,"sourceCodeEnd":103,"githubUrl":"https://github.com/pola-rs/polars/blob/fe841f959ef4d2ceefc05a310d33ed7b1ab24e5e/py-polars/src/polars/_dependencies.py#L67-L103","documentation":"`_ModuleAvailableProxy` wraps an optional dependency and imports it lazily on attribute access. The only attribute that deliberately fails is `__wrapped__` (to keep decorator introspection/doctests from triggering an import), raising `AttributeError`. Any other attribute goes through a real import; this specific error means something probed the proxy for `__wrapped__`.","triggerScenarios":"`hasattr(polars.<mod>_available, '__wrapped__')` or any `getattr(proxy, '__wrapped__')` access — typically from decorators, inspection tools, or doctest collection touching proxied module objects.","commonSituations":"Doctest runners and introspection frameworks examining module attributes; code treating the lazy-import proxy as a real module and probing decorator metadata.","solutions":["Nothing to fix — this AttributeError is intentional; catch/ignore it if your tooling probes attributes generically.","If your own code needs `__wrapped__`, access it on the real imported module rather than the proxy.","Use `getattr(proxy, '__wrapped__', None)` to avoid exception noise in generic introspection."],"exampleFix":"// before\nwrapped = mod_proxy.__wrapped__\n\n// after\nwrapped = getattr(mod_proxy, '__wrapped__', None)\nif wrapped is None:\n    ...","handlingStrategy":"type-guard","validationCode":"assert hasattr(polars.dependencies, 'pyarrow_available')","typeGuard":"def real_module_or_none(proxy) -> 'ModuleType | None':\n    return proxy._import() if getattr(proxy, '_module_available', False) else None","tryCatchPattern":"try:\n    wrapped = proxy.__wrapped__\nexcept AttributeError:\n    wrapped = None  # proxies intentionally lack __wrapped__","preventionTips":["Treat `_ModuleAvailableProxy` objects as opaque; do not probe decorator metadata on them.","Import the real module before doing deep introspection.","Skip `__wrapped__` checks in generic hasattr-based tooling for polars dependency proxies."],"tags":["python","polars","lazy-import","attributeerror","introspection"],"backgroundTag":"missing-optional-dependency","analyzedSha":"fe841f959ef4d2ceefc05a310d33ed7b1ab24e5e","analyzedAt":"2026-09-18T22:14:11.667Z","contentChangedAt":"2026-09-18T22:14:11.667Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}