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


Groups > comp.lang.python > #78801 > unrolled thread

Muddleheaded use of the "built-in" term

Started byMarco Buttu <marco.buttu@gmail.com>
First post2014-10-07 15:24 +0200
Last post2014-10-08 00:40 +1100
Articles 2 — 2 participants

Back to article view | Back to comp.lang.python


Contents

  Muddleheaded use of the "built-in" term Marco Buttu <marco.buttu@gmail.com> - 2014-10-07 15:24 +0200
    Re: Muddleheaded use of the "built-in" term Chris Angelico <rosuav@gmail.com> - 2014-10-08 00:40 +1100

#78801 — Muddleheaded use of the "built-in" term

FromMarco Buttu <marco.buttu@gmail.com>
Date2014-10-07 15:24 +0200
SubjectMuddleheaded use of the "built-in" term
Message-ID<m10pj3$82l$1@speranza.aioe.org>
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

[toc] | [next] | [standalone]


#78803

FromChris Angelico <rosuav@gmail.com>
Date2014-10-08 00:40 +1100
Message-ID<mailman.14660.1412689246.18130.python-list@python.org>
In reply to#78801
On Wed, Oct 8, 2014 at 12:24 AM, Marco Buttu <marco.buttu@gmail.com> wrote:
> 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"?

Yes, I think it's too late to change that. But it's no different from
any other word that has more than one variant of meaning; you have to
cope with the collisions. Is there any situation where it's ambiguous?
There are builtin name bindings, and there are built-in functions. The
former are provided by the language core and are thus available by
default; the latter are provided by the language core and thus do not
provide __code__. There's a connection between the meanings, but they
aren't identical.

What's a function? Obviously something created with def or lambda is.
Is a class a function? Is an object with a __call__ method a function?
Is a list comprehension a function? In different senses, all of them
are; but maybe what you want to ask is not "is this a function" but
"is this callable" (list comps aren't), or "does this create a new
local scope", or "does this have __code__" or something. Yet the
meanings of "function" are all related (mostly by external usage; list
comps by internal functionality), so it wouldn't make sense to decry
the collisions on that word.

I do see your issue, but I don't think this can be changed, nor is
worth changing.

ChrisA

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web