On Mon, Sep 28, 2020 at 2:10 PM Guido van Rossum <guido@python.org> wrote:
I just realize there is an ambiguity in PEP 484 regarding the ‘import ... as ...‘ syntax (and the other form).

I’ve always interpreted (and intended) this to mean ‘[from ...] import X as X’ (i.e. a redundant ‘as’ clause) and that is how it’s used in typeshed.

But it seems you are interpreting it as anything that uses an ‘as’ clause (as in Brett’s ‘dabuiltins’ example). And the text can indeed be read that way.

I think the key difference in view between the two interpretations is whether you view the `as` clause as part of the import statement or a convenient/implied assignment that's done post-import.

So if the semantics were `as` clauses that lead to a name lacking a leading underscore were consider exposed, that trips my brain up because now because _some_ forms of import dictate my exporting via a special rule that I have to avoid while other don't:

- `import X`; not exported
- `from X import Y`; not exported
- `from X import Y as Z`; exported; brain goes, "why is this form of import special when it comes to naming conventions and not the other forms?"

The `from X import Y as Y` is an explicit action where I'm opting to inline the exporting of the symbol makes more sense to me since it is not a normal thing to do and I have to actively think of the opt-in. Otherwise I assume people can unwrap the naming to explicitly export and have the tools support that as well:

from X import Y
Z = Y

-Brett
 

Do we have an indication that others are interpreting it that way? If not, maybe we should amend PEP 484 to clarify this.

—Guido
--
--Guido (mobile)
_______________________________________________
Typing-sig mailing list -- typing-sig@python.org
To unsubscribe send an email to typing-sig-leave@python.org
https://mail.python.org/mailman3/lists/typing-sig.python.org/
Member address: brett@python.org