Visitar URL original
`abc.ABC` incorrectly raise `Can't instantiate abstract` if attribute has `__getattr__` · Issue #107580 · python/cpython · GitHub
The Wayback Machine - https://web.archive.org/web/20250531022040/https://github.com/python/cpython/issues/107580
Skip to content

abc.ABC incorrectly raise Can't instantiate abstract if attribute has __getattr__ #107580

Closed as not planned
@Conchylicultor

Description

@Conchylicultor

Bug report

Reproduction

import abc

class A:

  def __getattr__(self, name: str):
    return A()


class B(abc.ABC):
  a: A = A()


B()  # TypeError: Can't instantiate abstract class B with abstract method a

a = A() is not a @abc.abstractmethod. I think abc just have some check if hasattr(B.a, '__is_abstractmethod__'), but this raise an error because A.__getattr__ dynamically create __is_abstractmethod__ on the fly

Your environment

  • CPython versions tested on: 3.11.1

Metadata

Metadata

Assignees

No one assigned

    Labels

    type-bugAn unexpected behavior, bug, or error

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions