Skip to content
Tcl Source Code View Ticket
Login

View Ticket

allow [namespace import] of same command

Closed / Accepted1230597fffffffffffffffffffffffffffffffffCreated 21 years agoUpdated 21 years ago
Descriptionplain2005-06-30 21:05:29
Consider the Tcl script:

namespace eval ::foo {
    proc foo {} {}
    namespace export foo
}
namespace eval ::bar {
    namespace import ::foo::foo
}

This script can only be eval'd
one time.  (If it's in a file, that
file can only be [source]d one
time).

The second attempt will
throw an error from the
[namespace import] attempt.
The error is meant to warn us
that the [namespace import]
is overwriting an existing command.

In examples like this one, though,
that warning is wrong-headed.
We're "overwriting" an import with
itself, something perfectly safe.

Worse, the import implementation code
has all the info it needs to check and
verify that this is perfectly safe, yet fails
to do so.

Much, much worse, the existing "fix"
for this problem is to add "-force" to
the [namespace import] which loses
all safety, even that which would be
useful.

Here's a patch to make [namespace import]
stop raising errors on "overwrites" of an
import over itself.  This is obviously a good
idea.  Less obvious whether a TIP is required.

This patch is all that's needed to fix
Tk Bug 1230576.
dgpplain2005-07-01 04:05:30
File Added - 140416: import.patch
msoferplain2005-07-01 04:26:19
Logged In: YES 
user_id=148712

Patch looks good at first sight. I do not think a TIP is
needed, this seems consistent with the following quote from
namespace.n:
"This command normally returns an error if an imported
command conflicts with an existing command."

This patch only changes the behaviour in case that there is
NO conflict. It could even be argued that it fixes a bug ;)

I see that one test was specifically looking for this
behaviour. Does itcl test for this too?
dkfplain2005-07-01 04:53:03
Logged In: YES 
user_id=79902

I agree with Miguel; fixing this is entirely reasonable.
(And who *cares* if this busts itcl?)
dgpplain2005-07-01 21:30:43
Logged In: YES 
user_id=80530


Here's the corresponding patch
for core-8-4-branch.
dgpplain2005-07-01 21:30:44
File Added - 140516: 1230597.patch
dgpplain2005-07-06 00:27:32
Logged In: YES 
user_id=80530


committed to both branches.
Log in (anonymous is fine) to add a comment.

Attachments: