
Dec. 14, 2019
12:24 a.m.
On Fri, Dec 13, 2019 at 06:27:41PM -0500, Wes Turner wrote:
Would the builtins import look like this:
if not hasattr(__builtins__, 'first'):
Not that. `__builtins__` is a private CPython implementation detail, so the above is always wrong in user code. Better: import builtins try: builtins.first except AttributeError: ... You don't even need the builtins import: try: first except AttributeError: ... Remember how we say "not every one-liner needs to be a builtin"? Why is this trivial one-line wrapper around next important enough to be a builtin?
import sys if sys.version_info[:2] < (3,9): from more_itertools.more import first
Feature detection is better and more reliable than version checks. -- Steven