On Tue, Nov 19, 2019 at 5:26 AM Random832 <[email protected]> wrote:
>
> On Mon, Nov 18, 2019, at 13:00, Andrew Barnert via Python-ideas wrote:
> > def f(a, b): return a**(b+1)
> > g = partial(f, b==2)
> > h = lambda x: f(x, 2)
> >
> > Python can’t tell the difference between f, g, and h; they’re all
> > variables. An IDE could keep track of the fact that f was bound by a
> > def statement, and g and h by assignment. But I’m not sure why you’d
> > want it to. After all, they’re all variables with callable values. Why
> > should f(2,3) be colored differently from g(4)?
>
> I think, more or less, "a function" can be regarded as "a *constant* whose
> value is callable and is not type-like" [where type-like includes types,
> abstract base classes, and type hint objects], regardless of how it was
> obtained.
>
If by "constant" you mean that they are immutable, then maybe; there
aren't very many mutable callables (by comparison to the huge number
of functions). But you can't assume that a function is as constant as
a string literal. Closures are more akin to lists than to literals -
every time you run the 'def' command, it creates you a brand new
function with whichever context it was given.
> Opinions may differ on whether "real variables" [either locals, or globals
> whose values actually do vary] and/or parameters of callable types (or
> type-like types) should or should not be highlighted the same way as a
> typical non-callable variable.
>
> Highlighting these would in any case require an editor with a deep
> understanding of the language (far beyond the typical regex-based syntax
> highlighters) and probably type annotated code, but that doesn't mean it
> wouldn't be useful.
>
verbose = print
if args.quiet:
def verbose(*a, **kw): pass
...
verbose("blah blah blah")
Is 'verbose' now a variable, a function, a constant, a global, or
what? How should it be highlighted?
ChrisA
_______________________________________________
Python-ideas mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at
https://mail.python.org/archives/list/[email protected]/message/SFAB2TURTNTUU5AKVOHSU4COG7CNEIAW/
Code of Conduct: http://python.org/psf/codeofconduct/