Best way of `using` without bring names into scope?

Is there a way to use a module without bringing its names into scope? I don’t need to extend any methods.

Specifically, using A brings type Foo into scope, but other code already defines Foo, so there is a name ambiguity and I actually don’t need A.Foo. I know I could do using A: x, y, z, but I’d rather just do A.x where needed because I don’t need much from A. The Summary of module usage makes it look like there’s no way to do what I want. For now I’m doing import A, but I don’t need to extend any methods, so that seems like a misuse. What’s the best way to do a Pythonic import? TIA.

You’re looking for import after all. Doing import A doesn’t let you extend the names of A. Only import A: some_name lets you do that.

1 Like

I thought that import A still allows me to extend methods in A but only if I qualify them like A.x(y) = .... At least that’s what the Summary of module usage implies.

You can also do using A: A

I find that construction useful when I want to be able to access foo from module A without pulling in the rest of its symbols, but I still want to be able to do

For example:

using A: foo, A


Wow, that’s counterintuitive! But that’s exactly what I’m trying to do. Thanks!

1 Like

No that has nothing to do with import. You can do that with using too. If the module is the only thing you need , just import, it’s the standard and most readable way.


Sorry, but what has nothing to do with import? Whether method extension is possible?

Correct. As long as you have module M, you can always extend a function func in it with M.func. It doesn’t matter how you get the module. It can be imported, usinged, simply assigned as in M = ....