Issue 4795: inspect.isgeneratorfunction inconsistent with other inspect functions (original) (raw)

Issue4795

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.

This issue has been migrated to GitHub: https://github.com/python/cpython/issues/49045

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:43 admin set github: 49045
2009-01-01 01:31:56 rhettinger set nosy: + rhettingermessages: +
2008-12-31 23:48:50 benjamin.peterson set status: open -> closedresolution: fixedmessages: + nosy: + benjamin.peterson
2008-12-31 22:47:06 steven.daprano create

Supported by The Python Software Foundation,
Powered by Roundup

Copyright © 1990-2022, Python Software Foundation
Legal Statements