homepage

This issue tracker has been migrated to GitHub , and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

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 2022年04月11日 14:56 by admin. 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
2022年04月11日 14:56:43adminsetgithub: 49045
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

AltStyle によって変換されたページ (->オリジナル) /