[docs] [issue28681] About function renaming in the tutorial

Steven D'Aprano report at bugs.python.org
Sun Nov 13 00:52:37 EST 2016


Steven D'Aprano added the comment:

I disagree that "aliasing" is more accurate.

We have a perfectly good name for symbols in Python: "name". A value (and that includes functions) can have multiple names. It seems to me that if we're to start distinguishing between names and aliases, then aliases have to be different from names. And the way I understand "alias" is that it is another symbol for a variable, not another symbol for the same value.

We wouldn't say that

    x = 1
    y = x

makes y an alias for x. y just happens to be a second name for the same value that x currently has. There's no guarantee that they will stay the same. Substitute a function object for the int 1, and you have the situation being discussed in the tutorial.

I would expect that aliases should not be effected by rebinding:

    x = 1
    y = alias(x)  # if such a thing existed
    x = 2
    assert y == 2

Obviously there's nothing in Python like that! This doesn't match Python's name binding model at all.

I think that talking about a "general aliasing" mechanism is exactly wrong. I think that the tutorial should emphasis the reality that functions are just ordinary values, like ints and floats and dicts and lists, and not try to indicate that there is something special or different about names bound to functions:

    def f(): ...
    g = f

is no different from the x = y example earlier.

----------
nosy: +steven.daprano

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue28681>
_______________________________________


More information about the docs mailing list