[Types-sig] Module Attribute visibility

Tim Peters tim_one@email.msn.com
Fri, 17 Dec 1999 06:00:06 -0500


[Paul]
> Okay, but doesn't Python already conflate declaration with
> initialization?

I don't think so.  Its only declaration today is "global"!

> When I refer to mymod.foo I am referring to an object that was
> assigned, somewhere to the name foo in the module mymod.

I don't follow this, unless you think of referring to mymod.foo as "a
declaration" -- I don't.  It's just a reference.

> Are we going to say that statically type checked code can only
> refer to declared (not merely assigned) variables in other
> modules?

I wouldn't say that, although I bet some people will want that as an option.

> Would it be safe to say that undeclared variables are simply not
> available for type checking?

Don't know what "not available" means.  Yell at me if it means more than
what you're talking about below.

> Would you suggest that this is even the case for functions? I.e.
>
> def foo( str ): return str*2
>
> is invisible to the type checker

Not invisible, but that its argument and its return type are (in the absence
of inference) both associated with the universal set (the set of all types),
with rules as sketched earlier (widening bindings only; "int = universal"
bad (& whether that's a compile-time error, or *potential* run-time error,
or compile-time warning, is an option); "universal = int" good).

> until we add:
>
> decl foo: str -> str
>
> Or would foo have an implicit declaration:
>
> decl foo: PyObject -> PyObject

Yes, your PyObject appears to be a spelling of what I called the "universal
set" above.  Although, since this *is* Python, you could probably drop the
"Py" prefix without risk of confusion <wink>.

> And if that foo has an implicit declaration, shouldn't this foo also:
>
> foo = lambda x: x*2

I can't imagine any reason why it shouldn't!  If we're disagreeing here, I
don't see how -- unless it's that you believe I mean something by
"declaration" and/or "initialization" that I don't.

All I was getting at is that

    decl x: Int = 5

(combining declaration with initialization) is more dubious than

    decl x: Int
    x = 5

(leaving declaration (1st line) separate from initialization (2nd line)) in
a language where some people clearly don't want to look at type declarations
*at all*.  Keeping the binding out of the declaration makes it trivial to
"comment it out", set an editor mode to suppress displaying "decl" lines,
copy decl lines into interface files, and so on.

different-purpose-different-statement-ly y'rs  - tim