variable scope in try ... EXCEPT block.

Ed Kellett e+python-list at kellett.im
Thu Jul 12 09:23:28 EDT 2018


On 2018-07-12 14:03, Chris Angelico wrote:
> Dealing with reference cycles is generally done *periodically* rather
> than immediately (CPython disposes of unreferenced objects immediately
> upon last deref). You can avoid having a dedicated cycle detection
> pass by using a mark-and-sweep GC, but that just means that *all*
> garbage is dealt with periodically rather than immediately. I can
> imagine having some sort of flag on every object that's involved in a
> cycle, and then doing a mini-GC every time any of those objects gets
> any dereferencing, but that would be ridiculously expensive. There are
> ALWAYS tradeoffs. How is Python's arrangement "the worst"?

It pays the cost of a reference counter and a garbage collector and the
language designers *still* feel like they have to add weird hacks like
the implicit del. I agree there are always tradeoffs. But it feels like
Python has made tradeoffs that should allow it to never worry about
cycles ever, and then it goes ahead and worries about cycles anyway.

> Personally, I think this would be better with an *actual* subscope.
> But apparently that's a ridiculously insane suggestion with no chance
> whatsoever of being accepted. Kinda like assignment expressions.

FWIW, I'd vastly prefer some kind of reconsidering of the scoping
approach to assignment expressions. I don't want to have a 10000th
iteration of the same old argument about them, but I think subscoping is
way more applicable: at least to me, it'd make all code more readable by
default, because it'd tend to make namespaces emptier and therefore
easier to hold in memory.

Could we fix:

  for x in something:
    blah(lambda a: a + x)

while we're at it?

Also, since we're well into the realm of crazy here, when are we making
nonlocal the default?

Ed



More information about the Python-list mailing list