0

Based on https://docs.python.org/2/library/abc.html, it seems abstract classes are available starting in version 2.6 (the top says "New in version 2.6.")

However, I cannot from abc import ABC, abstractmethod using python 2.7.16 as it produces the error:ImportError: cannot import name ABC but I can with python3+. So is abc not available for python 2.X?

David
  • 619
  • 2
  • 8
  • 15
  • Class `abc.ABC` is not available in 2.7 (as the linked documentation shows). – Michael Butscher Feb 14 '23 at 20:12
  • 2
    No, it implies that `abc.ABC` isn't available, which it isn't. It's just a convenience class to insert the metaclass, you can just use `abc.ABCMeta`. Of course, you really probably shouldn't be using python 2.7 to begin with – juanpa.arrivillaga Feb 14 '23 at 20:14
  • 2
    The module `abc` was added in 2.6, but this version of the module doesn't have the class `abc.ABC`. That was added in 3.4. – Barmar Feb 14 '23 at 20:14
  • sorry, I misunderstood the documentation. Unfortunately, the 2.7 is a unit test that I can't easily deprecate (it's part of a large codebase) – David Feb 14 '23 at 20:15

0 Answers0