Ticket UUID: | 1230597 | |||
Title: | allow [namespace import] of same command | |||
Type: | RFE | Version: | None | |
Submitter: | dgp | Created on: | 2005-06-30 21:05:29 | |
Subsystem: | 21. [namespace] | Assigned To: | dgp | |
Priority: | 5 Medium | Severity: | ||
Status: | Closed | Last Modified: | 2005-07-06 00:27:32 | |
Resolution: | Accepted | Closed By: | dgp | |
Closed on: | 2005-07-05 17:27:32 | |||
Description: |
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. | |||
User Comments: |
dgp added on 2005-07-06 00:27:32:
Logged In: YES user_id=80530 committed to both branches. dgp added on 2005-07-01 21:30:44: File Added - 140516: 1230597.patch dgp added on 2005-07-01 21:30:43: Logged In: YES user_id=80530 Here's the corresponding patch for core-8-4-branch. dkf added on 2005-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?) msofer added on 2005-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? dgp added on 2005-07-01 04:05:30: File Added - 140416: import.patch |