[Python-ideas] Re: Limit 'import as' syntax
30.03.20 15:50, jope...@hotmail.fr пише: As a result, `import os.path as p` stores os.path, not os, in p. This makes it effectively the same as `from os import path as p` No, it is not the same. For example, `from os import mkdir as mkd` works, but `import os.mkdir as mkd` is an error. ___ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to python-ideas-le...@python.org https://mail.python.org/mailman3/lists/python-ideas.python.org/ Message archived at https://mail.python.org/archives/list/python-ideas@python.org/message/SAEYXOHZGHYG7I34TOO22FK5X4HTXDYD/ Code of Conduct: http://python.org/psf/codeofconduct/
[Python-ideas] Re: Limit 'import as' syntax
As spotted by response, I did not mature enough my point to see that they could have a slight difference between both statements. This thread is no longer relevant. Thank you ___ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to python-ideas-le...@python.org https://mail.python.org/mailman3/lists/python-ideas.python.org/ Message archived at https://mail.python.org/archives/list/python-ideas@python.org/message/K7CX6HOQYT2HZQH3WYHXXEQYTJ4WTTDF/ Code of Conduct: http://python.org/psf/codeofconduct/
[Python-ideas] Re: Limit 'import as' syntax
You are right, I did not envisage the case where you could have name mangling between submodule and variable inside package __init__.py, which could lead to different behavior. So my statement is erroneous and this thread is no longer relevant. Thank you ___ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to python-ideas-le...@python.org https://mail.python.org/mailman3/lists/python-ideas.python.org/ Message archived at https://mail.python.org/archives/list/python-ideas@python.org/message/O25CKD6WEVFWIMHJEITJ7BAUVUTG7ZCE/ Code of Conduct: http://python.org/psf/codeofconduct/
[Python-ideas] Re: Limit 'import as' syntax
Maybe you should fill some feature requests to the linter projects, like flake8, so that they have an option to distinguish both ways so that one could point what is the "preferred way" for a given project. But I don't see any sense on even put a PEP 8 recommendation for this. On Mon, 30 Mar 2020 at 12:11, Joao S. O. Bueno wrote: > The part of "as X" of either "import foo.bar as X" or "from foo import bar > as X" does _one thing_ and is fully self-consistent. > > The part of "import foo.bar" and "from foo import bar" does different > things, that sometimes are interchangeable, > and in some cases may have different results - however, these are well > stablished, and overall, they don't > even "care" or "know" if the imported part is to be renamed with an "as X" > complement. > > For me that is "one obvious way to do it" and there is nothing of > "oounerintuitive" on that. > > Also, trying to change or limit this now, besides blocking behaviors that > sometimes are needed, > would introduce severe backwards incompatibility for no gain at all. > > js > -><- > > On Mon, 30 Mar 2020 at 11:54, Joseph Perez wrote: > >> There is no other advantage than respect of the Zen of Python (and I >> don't know how much it counts). Maybe it can simplify interpreter code, but >> I don't know about it and I doubt it. >> With that, it could help newcomers to Python to choose between the two >> syntaxes. (And I've already experienced team conflict about syntax) >> By the way, I think this issue is not fundamental, that's why a removal >> would actually maybe be too strong. >> ___ >> Python-ideas mailing list -- python-ideas@python.org >> To unsubscribe send an email to python-ideas-le...@python.org >> https://mail.python.org/mailman3/lists/python-ideas.python.org/ >> Message archived at >> https://mail.python.org/archives/list/python-ideas@python.org/message/FD5PIOEUFEQQWY475TYZPZF5SOKDQW3S/ >> Code of Conduct: http://python.org/psf/codeofconduct/ >> > ___ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to python-ideas-le...@python.org https://mail.python.org/mailman3/lists/python-ideas.python.org/ Message archived at https://mail.python.org/archives/list/python-ideas@python.org/message/55AZVP524SE3PNNET74VGJQ3KQQQXQXB/ Code of Conduct: http://python.org/psf/codeofconduct/
[Python-ideas] Re: Limit 'import as' syntax
The part of "as X" of either "import foo.bar as X" or "from foo import bar as X" does _one thing_ and is fully self-consistent. The part of "import foo.bar" and "from foo import bar" does different things, that sometimes are interchangeable, and in some cases may have different results - however, these are well stablished, and overall, they don't even "care" or "know" if the imported part is to be renamed with an "as X" complement. For me that is "one obvious way to do it" and there is nothing of "oounerintuitive" on that. Also, trying to change or limit this now, besides blocking behaviors that sometimes are needed, would introduce severe backwards incompatibility for no gain at all. js -><- On Mon, 30 Mar 2020 at 11:54, Joseph Perez wrote: > There is no other advantage than respect of the Zen of Python (and I don't > know how much it counts). Maybe it can simplify interpreter code, but I > don't know about it and I doubt it. > With that, it could help newcomers to Python to choose between the two > syntaxes. (And I've already experienced team conflict about syntax) > By the way, I think this issue is not fundamental, that's why a removal > would actually maybe be too strong. > ___ > Python-ideas mailing list -- python-ideas@python.org > To unsubscribe send an email to python-ideas-le...@python.org > https://mail.python.org/mailman3/lists/python-ideas.python.org/ > Message archived at > https://mail.python.org/archives/list/python-ideas@python.org/message/FD5PIOEUFEQQWY475TYZPZF5SOKDQW3S/ > Code of Conduct: http://python.org/psf/codeofconduct/ > ___ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to python-ideas-le...@python.org https://mail.python.org/mailman3/lists/python-ideas.python.org/ Message archived at https://mail.python.org/archives/list/python-ideas@python.org/message/YBO44XWDMY35CQ4ESPFIUZXWE4VNPF6Q/ Code of Conduct: http://python.org/psf/codeofconduct/
[Python-ideas] Re: Limit 'import as' syntax
There is no other advantage than respect of the Zen of Python (and I don't know how much it counts). Maybe it can simplify interpreter code, but I don't know about it and I doubt it. With that, it could help newcomers to Python to choose between the two syntaxes. (And I've already experienced team conflict about syntax) By the way, I think this issue is not fundamental, that's why a removal would actually maybe be too strong. ___ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to python-ideas-le...@python.org https://mail.python.org/mailman3/lists/python-ideas.python.org/ Message archived at https://mail.python.org/archives/list/python-ideas@python.org/message/FD5PIOEUFEQQWY475TYZPZF5SOKDQW3S/ Code of Conduct: http://python.org/psf/codeofconduct/
[Python-ideas] Re: Limit 'import as' syntax
joperez@hotmail.fr wrote: > There should be one-- and preferably only one --obvious way to do it. (from > The Zen of > Python https://www.python.org/dev/peps/pep-0020/) > However, in something as basic as import syntax, that's not the case. This > example comes > from PEP 221 (https://www.python.org/dev/peps/pep-0221/) > : > A slightly special case exists for importing sub-modules. The statement > import os.path > stores the module os locally as os, so that the imported submodule path is > accessible as > os.path. As a result, > import os.path as p > stores os.path, not os, in p. This makes it effectively the same as > from os import path as p > Not only it doesn't respect the Zen of Python, but it's also quite > counterintuitive > because as explained in the PEP, the behavior of import os.path as p is not > the same than import os.path, while from os import path as p is > quite consistent with or without as. > There is one case where import ... as ... is consistent (and justified IMHO), > that's for statements like import _thread as thread, only the imported object > is aliased (as from ... import ... as ... do). > Looking at the standard library, only few dozens of lines match the regex > ^import > \w+\.(\w|\.)+ as, while the other (equivalent) form has hundreds of matches. > That's why I propose to restrict the aliased import statement (import ... as > ...) to not be able to alias imported submodule, letting from ... import ... > as ... statement be the only to do it. > The roadmap could be to depreciate the statement with a warning in a few next > releases, to > remove finally remove the syntax. > (hoping my English is okay) `import ...` and `from ... import ...` does not behave in the same manner as it is explained in docs: https://docs.python.org/3/reference/simple_stmts.html#import. So they are not equivalent statements. `import os.path as p` and `from os import path as p` bind the same local name to the same object, that is true. However, they do in a quite different manner. And this difference can be relevant, for instance, when are dealing with circular imports (ok, I cannot remember any example of this right now). So I do not see how they are violating any principle in PEP 20 "The Zen of Python". Anyway, The Zen of Python is an inspirational document, not a law. Even it it was the law, any law has its exceptions and PEP 221 "Import As" presents and explains one useful exception. In my opinion... Thank you. ___ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to python-ideas-le...@python.org https://mail.python.org/mailman3/lists/python-ideas.python.org/ Message archived at https://mail.python.org/archives/list/python-ideas@python.org/message/MGLG5YJMDLDU3LHCJP2POCVFW33342LB/ Code of Conduct: http://python.org/psf/codeofconduct/
[Python-ideas] Re: Limit 'import as' syntax
On Tue, Mar 31, 2020 at 12:12 AM wrote: > That's why I propose to restrict the aliased import statement (`import ... as > ...`) to not be able to alias imported submodule, letting `from ... import > ... as ...` statement be the only to do it. > The roadmap could be to depreciate the statement with a warning in a few next > releases, to remove finally remove the syntax. > (hoping my English is okay) > Can you elaborate a bit more on what the advantage of restricting and removing this is? ChrisA ___ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to python-ideas-le...@python.org https://mail.python.org/mailman3/lists/python-ideas.python.org/ Message archived at https://mail.python.org/archives/list/python-ideas@python.org/message/JEMHSKVVRHMUI5DXQ3NBIFUBRZVWKL27/ Code of Conduct: http://python.org/psf/codeofconduct/