classification
Title: Regression in abc in combination with passing a function to issubclass
Type: behavior Stage: resolved
Components: Versions: Python 3.7
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: glaubich, izbyshev, levkivskyi
Priority: normal Keywords:

Created on 2018-09-21 08:28 by glaubich, last changed 2018-09-21 16:39 by levkivskyi. This issue is now closed.

Messages (5)
msg325975 - (view) Author: Christoph Glaubitz (glaubich) Date: 2018-09-21 08:28
I'm not sure if this is a bug, or a known breaking change. I didn't find anything related in the changelog, except for a rewrite of abc. But hovever, I want this to be documented.

In 3.7.0:

import abc
def f():
    pass

class A(metaclass=abc.ABCMeta):
    pass

issubclass(f, A)

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python3.7/abc.py", line 143, in __subclasscheck__
    return _abc_subclasscheck(cls, subclass)
TypeError: issubclass() arg 1 must be a class


python up to 3.6 (including 2.7) happily return false.

Found real world usage in osc-lib
* https://github.com/openstack/osc-lib/blob/46e2fb0a58fc06cfce1bb535f432405767d6b78b/osc_lib/utils/__init__.py#L495
* https://storyboard.openstack.org/#!/story/2003322
msg325977 - (view) Author: Christoph Glaubitz (glaubich) Date: 2018-09-21 08:44
Maybe this is just how it should have been working the entire time, and osc is just holding it wrong.

Since:

class B:
    pass

issubclass(f, B)

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: issubclass() arg 1 must be a class

... but:

issubclass(B, A)
False
msg325979 - (view) Author: Ivan Levkivskyi (levkivskyi) * (Python committer) Date: 2018-09-21 09:19
This was a conscious decision (i.e we decided that the old inconsistency is a bug). See https://bugs.python.org/issue33018 for previous discussion. What is your use case? If it is critical, we can reconsider this.
msg325983 - (view) Author: Christoph Glaubitz (glaubich) Date: 2018-09-21 10:47
I just realized this while trying to use the openstack command line tools on python3.7. After reading issue33018 and the fact that even in python2

class B:
    pass

def f():
    pass

issubclass(f, B)

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: issubclass() arg 1 must be a class

... I am sure, the new behavior is the correct one. I would be totally fine with closing this issue, and hoping not too many code depend on the strange old behavior :)
msg326005 - (view) Author: Ivan Levkivskyi (levkivskyi) * (Python committer) Date: 2018-09-21 16:39
OK, lets close this for now. We will see if there are any other situations.
History
Date User Action Args
2018-09-21 16:39:54levkivskyisetstatus: open -> closed
resolution: not a bug
messages: + msg326005

stage: resolved
2018-09-21 10:47:25glaubichsetmessages: + msg325983
2018-09-21 09:58:34izbyshevsetnosy: + izbyshev
2018-09-21 09:19:11levkivskyisetmessages: + msg325979
2018-09-21 09:06:06serhiy.storchakasetnosy: + levkivskyi
2018-09-21 08:44:27glaubichsetmessages: + msg325977
title: Regression in abc in combination with issubclass -> Regression in abc in combination with passing a function to issubclass
2018-09-21 08:28:36glaubichcreate