Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #78804

Muddleheaded use of the "built-in" term

Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!news.mixmin.net!feeds.phibee-telecom.net!newsfeed.xs4all.nl!newsfeed3.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <marco.buttu@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.003
X-Spam-Evidence '*H*': 0.99; '*S*': 0.00; 'beginner': 0.05; 'interpreter': 0.05; 'attribute': 0.07; 'method.': 0.07; 'builtin': 0.09; 'namespace': 0.09; 'referenced': 0.09; 'python': 0.11; 'builtins': 0.16; 'doc:': 0.16; 'expected,': 0.16; 'marco': 0.16; 'nameerror:': 0.16; 'namespace,': 0.16; 'surprises': 0.16; 'underlying': 0.16; 'bit': 0.19; 'everyone,': 0.19; 'skip:p 40': 0.19; 'not,': 0.20; 'written': 0.21; '>>>': 0.22; 'import': 0.22; 'header:User-Agent:1': 0.23; 'instance,': 0.24; 'module,': 0.24; 'skip:` 20': 0.24; 'math': 0.24; 'defined': 0.27; 'function': 0.29; 'explained': 0.31; 'inspect': 0.31; 'phone:': 0.31; 'url:python': 0.33; '(most': 0.33; 'not.': 0.33; 'subject:the': 0.34; 'could': 0.34; 'something': 0.35; 'late': 0.35; 'objects': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'false': 0.36; 'like,': 0.36; 'module.': 0.36; 'url:org': 0.36; 'changing': 0.37; 'so,': 0.37; 'too': 0.37; 'url:library': 0.38; 'whatever': 0.38; 'to:addr:python-list': 0.38; 'list,': 0.38; 'fact': 0.38; 'recent': 0.39; 'subject:" ': 0.39; 'to:addr:python.org': 0.39; 'either': 0.39; 'url:3': 0.61; 'course': 0.61; 'name': 0.63; 'term': 0.63; 'here': 0.66; 'header:Reply-To:1': 0.67; 'reply- to:no real name:2**0': 0.71; 'available:': 0.91
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:message-id:date:reply-to:user-agent:mime-version:to:subject :content-type:content-transfer-encoding; bh=3cJm+0+JfsNxUwWDEOxNy+pQ5ckUt9CUWotplo48wjI=; b=JE5zs93kDpNcvDMg2kQ1T0t4PBwrnyVoKDzCyOfT/74nQ9SiExxMmK24GBPkXw0OjY i4u0MerWfIh/0TlmoJgKtAx74/cgZJIl5iEE0sfhZxRK9BoZNp7ynvGSxC5p+GgqeHhP aghvHNR7EW486Fy4BkJ4xOdG4feT5Hbnj1pBoYlWWL0Ajf80AY8YfRP922uEiHbYLtUt eWsmh1hjYYxvLow9U4R6mBknnwKBefBF9lkuRYjsT7wEN+sFxibV/kZKb8K7TzlhoAb7 s+dUkUTRL6g3WjtwvFyd/eXhLXWHg5VYOazEG7+RlINRuggBtKZi760DnQnsc80pIKir H5MQ==
X-Received by 10.194.134.100 with SMTP id pj4mr4767320wjb.72.1412686945174; Tue, 07 Oct 2014 06:02:25 -0700 (PDT)
From Marco Buttu <marco.buttu@gmail.com>
X-Google-Original-From Marco Buttu <mbuttu@oa-cagliari.inaf.it>
Date Tue, 07 Oct 2014 15:02:22 +0200
User-Agent Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.1.2
MIME-Version 1.0
To python-list@python.org
Subject Muddleheaded use of the "built-in" term
Content-Type text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding 7bit
X-Mailman-Approved-At Tue, 07 Oct 2014 15:44:37 +0200
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
Reply-To mbuttu@oa-cagliari.inaf.it
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.14661.1412689479.18130.python-list@python.org> (permalink)
Lines 57
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1412689479 news.xs4all.nl 2978 [2001:888:2000:d::a6]:37248
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:78804

Show key headers only | View raw


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 in the doc:

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 or whatever underlying language"?

-- 
Marco Buttu

INAF-Osservatorio Astronomico di Cagliari
Via della Scienza n. 5, 09047 Selargius (CA)
Phone: 070 711 80 217
Email: mbuttu@oa-cagliari.inaf.it

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Muddleheaded use of the "built-in" term Marco Buttu <marco.buttu@gmail.com> - 2014-10-07 15:02 +0200

csiph-web