5

in many codes, i see classes with functions in them that they just used pass phrase with some comment upon them. like this native builtin function from python:

def copyright(*args, **kwargs): # real signature unknown
"""
interactive prompt objects for printing the license text, a list of
    contributors and the copyright notice.
"""
pass

i know pass does nothing, and its kind of apathetic and null phrase, but why programmers use such functions ?

and also there are some functions with return "" like:

def bin(number): # real signature unknown; restored from __doc__
"""
bin(number) -> string

Return the binary representation of an integer.

   >>> bin(2796202)
   '0b1010101010101010101010'
"""
return ""

why programmers use such things ?

anon
  • 433
  • 1
  • 8
  • 14

2 Answers2

6

Your IDE is lying to you. Those functions don't actually look like that; your IDE has made up a bunch of fake source code with almost no resemblance to the real thing. That's why it says things like # real signature unknown. I don't know why they thought this was a good idea.

The real code looks completely different. For example, here's the real bin (Python 2.7 version):

static PyObject *
builtin_bin(PyObject *self, PyObject *v)
{
    return PyNumber_ToBase(v, 2);
}

PyDoc_STRVAR(bin_doc,
"bin(number) -> string\n\
\n\
Return the binary representation of an integer or long integer.");

It's written in C, and it's implemented as a simple wrapper around the C function PyNumber_ToBase:

PyObject *
PyNumber_ToBase(PyObject *n, int base)
{
    PyObject *res = NULL;
    PyObject *index = PyNumber_Index(n);

    if (!index)
        return NULL;
    if (PyLong_Check(index))
        res = _PyLong_Format(index, base, 0, 1);
    else if (PyInt_Check(index))
        res = _PyInt_Format((PyIntObject*)index, base, 1);
    else
        /* It should not be possible to get here, as
           PyNumber_Index already has a check for the same
           condition */
        PyErr_SetString(PyExc_ValueError, "PyNumber_ToBase: index not "
                        "int or long");
    Py_DECREF(index);
    return res;
}
user2357112
  • 260,549
  • 28
  • 431
  • 505
  • I imagine JetBrains (for it is they) do this so that you can browse into library modules and eventually to a documented dead end, rather than just not allow you to follow a name to its definition. – Peter Wood Feb 11 '17 at 22:01
  • This is weird, seems like it could be worth a bug report – Chris_Rands Feb 12 '17 at 09:13
3

its a TBD (to be done) thing you know you will need this function, you know what to give it and you know what it returns, but you arent going to write it right now, so you make a "prototype"

sometimes packages will ship with these functions because they expect you to inherit them and overwrite them

Nullman
  • 4,179
  • 2
  • 14
  • 30
  • 3
    A plausible guess, but the real reason is completely different. Note that these are built-in objects like the builtin `bin` function or the `copyright` object that exists so you can type `copyright` in interactive mode and get a copyright message. They're already implemented. – user2357112 Feb 11 '17 at 21:54