Why are classes listed in the list of built
The Python docs lists property() as a built-in function.
However, the function description has the keyword "class" in front of it in the docs.
class property (fget=None, fset=None, fdel=None, doc=None)
This also happens with
class set ([iterable])
and
class slice (stop)
What does this mean? - why are classes listed under built-in functions. Is this just a documentation issue or is there a technical reason?
EDIT: I am not asking about how property() works.
The Python glossary defines a function as:
A series of statements which returns some value to a caller. It can also be passed zero or more arguments which may be used in the execution of the body.
A class can be passed arguments, and returns a value to the caller, so arguably by this definition classes are functions*.
In addition (as deceze points out in the comments), a class should always return an instance of itself – set
, property
, slice
, etc. all return instances of set
, property
, slice
, etc. respectively – so set
, property
and friends are all also classes, and so they are documented as such:
class set ([iterable])
meaning that set
is a class, not that it returns one.
I would guess that set
etc. are documented in the "built-in functions" page because a) they are callable, and b) it's convenient to have all the documentation for "things you can call" in one place.
*Strictly speaking, isinstance(C, types.FunctionType)
is false for any class C
(as far as I can tell), but classes are certainly callables ( isinstance(C, typing.Callable)
is true), which is maybe a more useful property to think about.
上一篇: 在Typescript中扩展基类属性
下一篇: 为什么在列表中列出类