Skip to content

__getattr__ seems to compile to a non-special method on mypy 0.910 #887

@RonnyPfannschmidt

Description

@RonnyPfannschmidt

using mypy 0.910
given

class DistFacade:
    """Emulate a pkg_resources Distribution"""

    def __init__(self, dist: importlib_metadata.Distribution):
        self._dist = dist

    @property
    def project_name(self) -> str:
        return cast(str, self._dist.metadata["name"])

    def __getattr__(
        self, attr: str, default: Optional[object] = None
    ) -> Optional[object]:
        return cast(Optional[object], getattr(self._dist, attr, default))

    def __dir__(self) -> List[str]:
        return sorted(dir(self._dist) + list(super().__dir__()))

i observe

(Pdb) dist
<pluggy._entrypoints.DistFacade object at 0x7f95925220d0>
(Pdb) dist.__getattr__
<built-in method __getattr__ of DistFacade object at 0x7f95925220d0>
(Pdb) dist.__getattr__("version")
'3.4.1'
(Pdb) getattr(dist, "version")
*** AttributeError: 'DistFacade' object has no attribute 'version'
(Pdb) dist.version
*** AttributeError: 'DistFacade' object has no attribute 'version'

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions