
Here's some datapoints on typeshed for the relevant use of `[from ...] import X as Y`. Seems like a number of them are intended as re-exports. I personally like `import X as X` and so would be happy to volunteer to change existing typeshed definitions, if it allows us to more cleanly translate concepts to .py / correctly interface Brett's code. In [*6*]: *import* *ast* ...: *from* *pathlib* *import* Path ...: ...: *def* find_realiases(filename): ...: *with* open(filename) *as* f: ...: module = ast.parse(f.read()) ...: aliases = [node *for* node *in* ast.walk(module) *if* isinstance(node, ast.alias)] ...: realiased = [a *for* a *in* aliases *if* a.asname *and* a.asname != a.name.split(".")[-1] *and* *not* a.asname.startswith("_")] ...: *for* alias *in* realiased: ...: relpath = filename.relative_to(Path.home() / "dev/typeshed") ...: print(f"*{*str(relpath)*:*60*}* *{*alias.name*}* as *{* alias.asname*}*") ...: ...: ...: *for* p *in* sorted((Path.home() / "dev/typeshed").glob("**/*.pyi" )): ...: find_realiases(p) ...: stdlib/2/collections.pyi AbstractSet as Set stdlib/2/future_builtins.pyi ifilter as filter stdlib/2/future_builtins.pyi imap as map stdlib/2/future_builtins.pyi izip as zip stdlib/2/md5.pyi md5 as new stdlib/2/os/__init__.pyi OSError as error stdlib/2/os/__init__.pyi _PathLike as PathLike stdlib/2and3/_dummy_threading.pyi _ExceptHookArgs as ExceptHookArgs stdlib/2and3/contextlib.pyi ContextManager as AbstractContextManager stdlib/2and3/contextlib.pyi AsyncContextManager as AbstractAsyncContextManager stdlib/2and3/plistlib.pyi Dict as DictT stdlib/2and3/threading.pyi _ExceptHookArgs as ExceptHookArgs stdlib/3/collections/__init__.pyi AbstractSet as Set stdlib/3/os/__init__.pyi OSError as error stdlib/3/os/__init__.pyi _PathLike as PathLike stdlib/3/platform.pyi devnull as DEV_NULL third_party/2/six/__init__.pyi StringIO as BytesIO third_party/2/six/moves/__init__.pyi __builtin__ as builtins third_party/2/six/moves/__init__.pyi raw_input as input third_party/2/six/moves/__init__.pyi reload as reload_module third_party/2/six/moves/__init__.pyi xrange as range third_party/2/six/moves/__init__.pyi StringIO as cStringIO third_party/2/six/moves/__init__.pyi ifilter as filter third_party/2/six/moves/__init__.pyi ifilterfalse as filterfalse third_party/2/six/moves/__init__.pyi imap as map third_party/2/six/moves/__init__.pyi izip as zip third_party/2/six/moves/__init__.pyi izip_longest as zip_longest third_party/2/six/moves/__init__.pyi getcwd as getcwdb third_party/2/six/moves/__init__.pyi getcwdu as getcwd third_party/2/six/moves/__init__.pyi quote as shlex_quote third_party/2/six/moves/urllib/parse.pyi unquote as unquote_to_bytes third_party/2and3/Crypto/Protocol/KDF.pyi SHA as SHA1 third_party/2and3/boto/compat.pyi encodestring as encodebytes third_party/2and3/click/types.pyi _ParamType as ParamType third_party/2and3/dateutil/rrule.pyi weekday as weekdaybase third_party/2and3/flask/templating.pyi Environment as BaseEnvironment third_party/2and3/flask/wrappers.pyi Request as RequestBase third_party/2and3/flask/wrappers.pyi Response as ResponseBase third_party/2and3/google/protobuf/map_unittest_pb2.pyi ForeignMessage as ForeignMessage1 third_party/2and3/jinja2/_compat.pyi quote_from_bytes as url_quote third_party/2and3/jinja2/_compat.pyi quote as url_quote third_party/2and3/jinja2/compiler.pyi iskeyword as is_python_keyword third_party/2and3/jinja2/defaults.pyi FILTERS as DEFAULT_FILTERS third_party/2and3/jinja2/defaults.pyi TESTS as DEFAULT_TESTS third_party/2and3/requests/adapters.pyi exceptions as urllib3_exceptions third_party/2and3/requests/exceptions.pyi HTTPError as BaseHTTPError third_party/2and3/requests/models.pyi exceptions as urllib3_exceptions third_party/2and3/werkzeug/_compat.pyi StringIO as BytesIO third_party/2and3/werkzeug/_compat.pyi StringIO as BytesIO third_party/2and3/werkzeug/contrib/securecookie.pyi new as hmac third_party/2and3/werkzeug/debug/__init__.pyi BaseRequest as Request third_party/2and3/werkzeug/debug/__init__.pyi BaseResponse as Response third_party/2and3/werkzeug/test.pyi Request as U2Request third_party/2and3/werkzeug/test.pyi Request as U2Request third_party/2and3/werkzeug/testapp.pyi BaseRequest as Request third_party/2and3/werkzeug/testapp.pyi BaseResponse as Response third_party/3/aiofiles/__init__.pyi _os as os third_party/3/six/moves/__init__.pyi range as xrange third_party/3/six/moves/__init__.pyi reload as reload_module third_party/3/six/moves/__init__.pyi StringIO as cStringIO third_party/3/six/moves/__init__.pyi quote as shlex_quote third_party/3/waitress/compat.pyi parse as urlparse On Mon, 28 Sep 2020 at 14:10, 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.
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: hauntsaninja@gmail.com