Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!news.stack.nl!aioe.org!.POSTED!not-for-mail From: Marco Buttu Newsgroups: comp.lang.python Subject: Muddleheaded use of the "built-in" term Date: Tue, 07 Oct 2014 15:24:54 +0200 Organization: Aioe.org NNTP Server Lines: 51 Message-ID: NNTP-Posting-Host: MBLBCCOsfV5U0tI+T2+Z2A.user.speranza.aioe.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit X-Complaints-To: abuse@aioe.org User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.1.2 X-Notice: Filtered by postfilter v. 0.8.2 Xref: csiph.com comp.lang.python:78801 I always thought the builtin objects were those we can get from the `builtins` module, that is those always available. In fact the "Built-in Functions" documentation: https://docs.python.org/3/library/functions.html says: """The Python interpreter has a number of functions and types built into it that are always available. They are listed here in alphabetical order""". The functions in the documentation list, as expected, are the same functions we get from the `builtins` module. Now, is `math.sin` builtin? Of course not, because it is not an attribute of builtins: >>> import builtins >>> hasattr(builtins, 'sin') False and in fact it is not always available: >>> sin Traceback (most recent call last): ... NameError: name 'sin' is not defined But what happens if I want to check by using `inspect.isbuiltin`? The answer surprises me: >>> import inspect >>> print(inspect.isbuiltin.__doc__.split('\n')[0]) Return true if the object is a built-in function or method. >>> import math >>> inspect.isbuiltin(math.sin) True That's because the term "built-in" here means "written in C", as explained here: https://docs.python.org/3/library/types.html#types.BuiltinMethodType So, we have built-in objects that are always available, whose names live in the builtin namespace, and other built-in objects that do not live in the builtin namespace :/ By using the same word (built-in) to indicate either objects written in C or objects referenced by the builtin namespace could be a bit muddler for everyone, beginner or not. Is it too late for changing the name of the `builtin` namespace in something like, for instance, `root` namespace, or using the name "core" (inspect.iscore(), types.CoreFunctionType, ecc.) to indicate "written in C"? -- Marco Buttu