Proposal: local variable declarations and type advice

Courageous jkraska at san.rr.com
Mon Feb 25 23:26:00 EST 2002


>1) add a local declaration, similar in syntax to Python's existing global
>   declaration,...

Python's current "global" directive notionally "imports" the global variable
into the local namespace and short-circuits the automatic creation of a local.
Yours is the opposite: instead of using an outer variable, force the creation
of a local. Personally, I like this.

The list part of me wants:

	x = 3
	let ( x ):
		x = 5

I might call it something other than "let" to make it Pythonic, though.

>2) Add a compiler option similar to Perl's "use strict",

This has been brought up before. Personally, I favor the idea of a directive
of some kind, on per module basis, that affects that module for that module's
data. One of the reasons you're not seeing too many people clamour for this
kind of thing, however, is that misspellings are (so it is claimed, and so my
own personal experience suggests) actually a relatively scarce cause of Python
problems.

You can get some of this kind of behavior _now_ by the way. Just implement
a class which doesn't allow setattr to work on an instance for any variable
which doesn't likewise exist in it class.

*Poof, Guido uses his time machine*

>   Example 2:
>     local x(int)
>     x = "banana"    # implementation-dependent behavior

I disagree here. If you've gone to the trouble of declaring something,
to get full use, you need a defined error; further, it would be helfpul
if this occured prior to execution.

There's some good cause for resistance to this. One of those things which
keeps Python Pythonic is it's concise expressivity. Declarations foil that.

C//




More information about the Python-list mailing list