classification
Title: inspect.isgeneratorfunction inconsistent with other inspect functions
Type: behavior Stage:
Components: Library (Lib) Versions: Python 2.6
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: benjamin.peterson, rhettinger, steven.daprano
Priority: normal Keywords:

Created on 2008-12-31 22:47 by steven.daprano, last changed 2009-01-01 01:31 by rhettinger. This issue is now closed.

Messages (3)
msg78661 - (view) Author: Steven D'Aprano (steven.daprano) * (Python committer) Date: 2008-12-31 22:47
The inspect isSOMETHING() functions all return True or False, except 
for isgeneratorfunction(), which returns True or None.

The body of the function is very brief:

if (isfunction(object) or ismethod(object)) and \
        object.func_code.co_flags & CO_GENERATOR:
        return True

The behaviour can be made consistent with the other routines by either 
appending "else: return False", or changing the body to:

return bool(
  (isfunction(object) or ismethod(object)) and
   object.func_code.co_flags & CO_GENERATOR)
msg78667 - (view) Author: Benjamin Peterson (benjamin.peterson) * (Python committer) Date: 2008-12-31 23:48
Fixed in r68112.
msg78674 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2009-01-01 01:31
This can be simplified to just:

    return (isfunction(object) or ismethod(object)) and \
         object.func_code.co_flags & CO_GENERATOR

No need for patterns like:

  if cond:
     return True
  return False
History
Date User Action Args
2009-01-01 01:31:56rhettingersetnosy: + rhettinger
messages: + msg78674
2008-12-31 23:48:50benjamin.petersonsetstatus: open -> closed
resolution: fixed
messages: + msg78667
nosy: + benjamin.peterson
2008-12-31 22:47:06steven.dapranocreate