{"record":{"id":"09189ed34f43658b","repo":"pypa/pip","slug":"base-parameter-in-fn-is-none-either-overri","errorCode":null,"errorMessage":"`base` parameter in `_fn` is `None`. Either override this method or check the parameter first.","messagePattern":"`base` parameter in `_fn` is `None`\\. Either override this method or check the parameter first\\.","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"src/pip/_vendor/pkg_resources/__init__.py","lineNumber":1744,"sourceCode":"\n    def _has(self, path) -> bool:\n        raise NotImplementedError(\n            \"Can't perform this operation for unregistered loader type\"\n        )\n\n    def _isdir(self, path) -> bool:\n        raise NotImplementedError(\n            \"Can't perform this operation for unregistered loader type\"\n        )\n\n    def _listdir(self, path) -> list[str]:\n        raise NotImplementedError(\n            \"Can't perform this operation for unregistered loader type\"\n        )\n\n    def _fn(self, base: str | None, resource_name: str):\n        if base is None:\n            raise TypeError(\n                \"`base` parameter in `_fn` is `None`. Either override this method or check the parameter first.\"\n            )\n        self._validate_resource_path(resource_name)\n        if resource_name:\n            return os.path.join(base, *resource_name.split('/'))\n        return base\n\n    @staticmethod\n    def _validate_resource_path(path):\n        \"\"\"\n        Validate the resource paths according to the docs.\n        https://setuptools.pypa.io/en/latest/pkg_resources.html#basic-resource-access\n\n        >>> warned = getfixture('recwarn')\n        >>> warnings.simplefilter('always')\n        >>> vrp = NullProvider._validate_resource_path\n        >>> vrp('foo/bar.txt')\n        >>> bool(warned)","sourceCodeStart":1726,"sourceCodeEnd":1762,"githubUrl":"https://github.com/pypa/pip/blob/f399c3718970b1b0e2478dac5296eb62679a9b86/src/pip/_vendor/pkg_resources/__init__.py#L1726-L1762","documentation":"Raised by NullProvider._fn() when the `base` argument is None. _fn() joins base with the resource_name to form a filesystem path; if base (typically the module's directory, derived from module.__file__) is None, there is no path root to join against, so TypeError is raised. This happens when the module has no __file__ attribute.","triggerScenarios":"Calling a resource API on a module that has no __file__ (e.g. a built-in module, a namespace package, a module created dynamically, or a frozen module without a file path), so NullProvider.__init__ sets self.module_path = '' and base ends up None.","commonSituations":"Trying to access resources of a built-in module (like 'os' or 'json' in some contexts), a namespace package, or a module loaded in an embedded/frozen environment where __file__ is absent.","solutions":["Ensure the target package/module has a real __file__ on the filesystem before using pkg_resources resource APIs.","Use importlib.resources which handles package resources more robustly for packages without __file__.","Override _fn() in a custom provider if you control the loader and have an alternative path root."],"exampleFix":"// before\n# module is a namespace pkg without __file__\npath = provider._fn(provider.module_path, 'data.txt')  # module_path derived None\n// after\n# use importlib.resources for packages without __file__\nimport importlib.resources\nwith importlib.resources.files('mypkg') as pkg_dir:\n    path = pkg_dir / 'data.txt'","handlingStrategy":"type-guard","validationCode":"import importlib.resources\n# prefer importlib.resources for modules without __file__\nif getattr(module, '__file__', None) is None:\n    raise RuntimeError(f'{module} has no __file__; use importlib.resources')","typeGuard":"def module_has_file(module) -> bool:\n    return getattr(module, '__file__', None) is not None","tryCatchPattern":"try:\n    provider._fn(provider.module_path, name)\nexcept TypeError:\n    # module has no __file__; fall back to importlib.resources","preventionTips":["Check module.__file__ before using pkg_resources resource APIs.","Use importlib.resources for namespace/frozen packages."],"tags":["pkg-resources","resources","filesystem","loader"],"backgroundTag":null,"analyzedSha":"f399c3718970b1b0e2478dac5296eb62679a9b86","analyzedAt":"2026-08-08T23:01:42.227Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}