on 2014/01/03 14:23, Mark Wu wrote:
Hi Aline,
I would like to start a discussion about the code style for importing
modules by this chance.
I saw you and Rodrigo had reorganized the "import" statements(commit
65f6ad3 and e467b32).
But personally, I don't agree with the rule you're following. It
doesn't comply with PEP8 and bring
extra unnecessary rules.
1. Currently, the kimchi imports and external imports are separated.
But according to pep8:
we still need differentiate the standard library and third-party
library. So we just have three groups
at most and put a blank line between each groups. [1]
2. For better looking, we can further organize the imports in each group:
A. Sort by the import statement: all imports starting with
'import' are put together while
all imports starting with 'from' are put together. But we
don't need an explicit separating line
between them
B. Sort by module name following the first word ('import' or
'from')
For this patch, I don't think we need two blank to separate them
because they belongs to the same group.
Does it make thanks for you?
Agree. In a word, I think it should like following.
import standardLibA
import standardLibB
from standardLibX.Y import ...
from standardLibX.Z import ...
import thirdPartyLibA
import thirdPartyLibB
from thirdPartyLibX.Y import ...
from thirdPartyLibX.Z import ...
import kimchiLibA
import kimchiLibB
from kimchiLibX.Y import ...
from kimchiLibX.Z import ...
Since almost all Python projects agree with PEP 8, the current rule is
very counterintuitive to me (especially the
two-blank-line-before-kimchi-import rule). I think the rule suggested by
Mark is more friendly to me. All PEPs are discussed by lots of Python
developers, we should follow this collective intelligence unless we have
very good reason or particular use case to break it.
--
Thanks and best regards!
Zhou Zheng Sheng / 周征晟
E-mail: zhshzhou(a)linux.vnet.ibm.com
Telephone: 86-10-82454397