# Allow import (some,list,of,modules,with,parenthesis)

**URL:** <https://discuss.python.org/t/allow-import-some-list-of-modules-with-parenthesis/77001>\
**Category:** Ideas\
**Created:** [January 13, 2025, 5:11pm UTC](https://discuss.python.org/t/allow-import-some-list-of-modules-with-parenthesis/77001 "2025-01-13T17:11:40Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![marky1991](https://avatars.discourse-cdn.com/v4/letter/m/9fc348/32.png) [@marky1991](https://discuss.python.org/u/marky1991)\
**Post date:** [January 13, 2025, 5:11pm UTC](https://discuss.python.org/t/allow-import-some-list-of-modules-with-parenthesis/77001/1 "2025-01-13T17:11:40Z")

</div>

Basically, I think the import statement ought to accept parenthesis, just as “from blah import (a,b,c)” does.

Ie this code, which is currently a syntax error:

```python
import (os, sys, ...
        importlib)

```

ought to be accepted and be equivalent to

```python
import os, sys, ..., importlib

```

Currently, the workaround is to simply break this up into separate import statements, but I don’t see any benefit to forcing that split and the inconsistency with “from blah import (a,b,c)” is awkward and surprising imo. (I’ve been using python since ~2.6 and forgot that this wasn’t allowed.)

This came up tangentially last year in another thread, [Parentheses in global statement](https://discuss.python.org/t/parentheses-in-global-statement/31858) , but there the discussion was more about the global/nonlocal statements and got into debates about functional need there, with not much debate centered around this proposal. Here, I’m specifically and exclusively advocating for parenthesis for the simple import statement.

I’ve searched my old emails and have searched in discourse and don’t see any discussions specifically about this topic, but if anyone is aware of any, please let me know.

Thanks

---

<div class="post-metadata">

**Author:** ![bwoodsend](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/bwoodsend/32/4027_2.png) [@bwoodsend](https://discuss.python.org/u/bwoodsend)\
**Post date:** [January 13, 2025, 6:42pm UTC](https://discuss.python.org/t/allow-import-some-list-of-modules-with-parenthesis/77001/2 "2025-01-13T18:42:19Z")

</div>

> [@marky1991](#):
>
> Currently, the workaround is to simply break this up into separate import statements

I don’t understand. The workaround would be to remove the unnecessary brackets. Unless perhaphs you wanted to be able to write:

```python
import (
    os,
    sys,
    importlib,
)

```

Is that why you’d want this?

---

<div class="post-metadata">

**Author:** ![Rosuav](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/rosuav/32/3429_2.png) [@Rosuav](https://discuss.python.org/u/Rosuav)\
**Post date:** [January 13, 2025, 6:59pm UTC](https://discuss.python.org/t/allow-import-some-list-of-modules-with-parenthesis/77001/3 "2025-01-13T18:59:00Z")

</div>

Not really sure what the point is here. If you’re wrapping it across lines anyway, why not just put the word “import” at the start of each line?

---

<div class="post-metadata">

**Author:** ![marky1991](https://avatars.discourse-cdn.com/v4/letter/m/9fc348/32.png) [@marky1991](https://discuss.python.org/u/marky1991)\
**Post date:** [January 13, 2025, 8:09pm UTC](https://discuss.python.org/t/allow-import-some-list-of-modules-with-parenthesis/77001/4 "2025-01-13T20:09:00Z")

</div>

Yes, I want the ability to wrap my lines on multiple lines. A real example:

```python
import functools, nose, random, collections, time, datetime, time, datetime, itertools, \
        decimal, os, re, inspect, importlib

```

Here, the line runs past 90 chars, which I try to prevent in my codebase. (Not slavishly, but obviously this line can’t go on forever)

As acknowledged, this could also be written:

```python
import functools, nose, random, collections, time, datetime, time, datetime, itertools
import decimal, os, re, inspect, importlib

```

and with the proposal:

```python
import (functools, nose, random, collections, time, datetime, time, datetime, itertools,
        decimal, os, re, inspect, importlib)

```

I personally feel the form with parenthesis is slightly more clear, though obviously it’s subjective. I also appreciate the consistency with ‘from module import (…)’.

Obviously this is not a critical omission (python is so old now, there are no critical omissions left), but why is the language better by disallowing parentheses here?

---

<div class="post-metadata">

**Author:** ![Nineteendo](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/nineteendo/32/19122_2.png) [@Nineteendo](https://discuss.python.org/u/Nineteendo)\
**Post date:** [January 13, 2025, 9:00pm UTC](https://discuss.python.org/t/allow-import-some-list-of-modules-with-parenthesis/77001/5 "2025-01-13T21:00:37Z")

</div>

Also note that you can do this:

```python
import os, \
       sys, \
       importlib

```

---

<div class="post-metadata">

**Author:** ![sirosen](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/sirosen/32/8478_2.png) [@sirosen](https://discuss.python.org/u/sirosen)\
**Post date:** [January 13, 2025, 9:53pm UTC](https://discuss.python.org/t/allow-import-some-list-of-modules-with-parenthesis/77001/6 "2025-01-13T21:53:48Z")

</div>

> [@marky1991](#):
>
> why is the language better by disallowing parentheses here?

Because the more ways there are to do something, the more ways it will be done. There’s value in consistency.

The spirit of this suggestion seems to be “why not?” And I counter: “why?”

New syntax has a cost. It needs to be justified.

---

<div class="post-metadata">

**Author:** ![storchaka](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/storchaka/32/217_2.png) [@storchaka](https://discuss.python.org/u/storchaka)\
**Post date:** [January 13, 2025, 9:56pm UTC](https://discuss.python.org/t/allow-import-some-list-of-modules-with-parenthesis/77001/7 "2025-01-13T21:56:14Z")

</div>

Taking into account that such style directly contradicts PEP 8, there is a little chance to accept this feature.

---

<div class="post-metadata">

**Author:** ![marky1991](https://avatars.discourse-cdn.com/v4/letter/m/9fc348/32.png) [@marky1991](https://discuss.python.org/u/marky1991)\
**Post date:** [January 13, 2025, 10:07pm UTC](https://discuss.python.org/t/allow-import-some-list-of-modules-with-parenthesis/77001/8 "2025-01-13T22:07:19Z")

</div>

I feel I’ve already answered that (you can of course feel that the benefits do not outweigh the costs, but my argument is not ‘why not?’):

A) it’s slightly more readable  
B) it’s more consistent with other existing syntax in the language (`from W import (X, Y, Z)`)

Re PEP 8: I don’t understand, PEP 8 is only the style guide for cpython internal code, why is it relevant to the discussion of what is accepted syntactically? If this argument were to be taken seriously, why is the form `import X, Y, Z` accepted by the parser?

---

<div class="post-metadata">

**Author:** ![blhsing](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/blhsing/32/25812_2.png) [@blhsing](https://discuss.python.org/u/blhsing)\
**Post date:** [January 14, 2025, 1:39am UTC](https://discuss.python.org/t/allow-import-some-list-of-modules-with-parenthesis/77001/9 "2025-01-14T01:39:25Z")

</div>

> [@marky1991](#):
>
> A) it’s slightly more readable

I think you’ll have a slightly better argument of readability if instead of:

```python
import (os, sys, ...
        importlib)

```

you put each module name/path on a separate line:

```python
import (
    os,
    sys,
    importlib,
)

```

so that it’s at least as diff-friendly as the status quo.

> [@](#):
>
> B) it’s more consistent with other existing syntax in the language (`from W import (X, Y, Z)`)

While I agree with the consistency argument, I can see why the devs may think it would generate unnecessary churns without offering any functional benefit over the status quo of writing a separate import statement for each module.

Maybe there can be additional functionalities to justify a new syntax, such as an `as` clause:

```python
import (
    os,
    sys,
    importlib,
) as _private # a simple namespace object

_private.sys.exit(0)

```

or maybe _if_ the `async import` statement from [Async imports to reduce startup times](https://discuss.python.org/t/async-imports-to-reduce-startup-times/69732) ever reaches consensus in the future, it will be more apparent that repeatedly writing `async import` statements:

```python
async import os
async import sys
async import importlib

```

is too much clutter compared to:

```python
async import (
    os,
    sys,
    importlib,
)

```

Neither is too compelling still though.

---

<div class="post-metadata">

**Author:** ![sirosen](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/sirosen/32/8478_2.png) [@sirosen](https://discuss.python.org/u/sirosen)\
**Post date:** [January 14, 2025, 3:29am UTC](https://discuss.python.org/t/allow-import-some-list-of-modules-with-parenthesis/77001/10 "2025-01-14T03:29:10Z")

</div>

> [@marky1991](#):
>
> I feel I’ve already answered that (you can of course feel that the benefits do not outweigh the costs, but my argument is not ‘why not?’):
> 
> A) it’s slightly more readable  
> B) it’s more consistent with other existing syntax in the language (`from W import (X, Y, Z)`)

Okay, maybe I was unfair in how I characterized your presentation. I do not feel that you’ve demonstrated the value added to be anywhere near the cost of the addition. IMO the justification you’ve given is very weak.

Every piece of code working with ast, libcst, and their ilk is potentially negatively impacted when syntax changes. So a syntax change has to “do enough” to be worth it. Some things are worth the downsides. Is this?

You cite readability. Readability needs demonstration, as it’s a largely subjective topic. You haven’t shown how the new syntax is more readable than the alternatives. I think an import per line reads just fine.

You also cite consistency with FromImport. Here I agree with you that it would be better in a perfect world for the two to align. But I view it as a pretty minor and unimportant inconsistency.

If the change didn’t have any cost, I’d be completely neutral towards it. I wouldn’t use the style, others would, and that would be fine. But it’s not 0 cost. If I’m going to have to do a bunch of maintenance on all of my linters and formatting tools, I’d like it to be well justified.

---

<div class="post-metadata">

**Author:** ![jsbueno](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/jsbueno/32/1210_2.png) [@jsbueno](https://discuss.python.org/u/jsbueno)\
**Post date:** [January 16, 2025, 1:40pm UTC](https://discuss.python.org/t/allow-import-some-list-of-modules-with-parenthesis/77001/11 "2025-01-16T13:40:49Z")

</div>

Well, that is hardly a good argument: if this syntax ever comes true, Pep 8 would likely be accommodated for this to be the preferred way to do it, since it implies in the same readability of one import per line, without the repetition of the `import` keyword)

---

<div class="post-metadata">

**Author:** ![jsbueno](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/jsbueno/32/1210_2.png) [@jsbueno](https://discuss.python.org/u/jsbueno)\
**Post date:** [January 16, 2025, 1:44pm UTC](https://discuss.python.org/t/allow-import-some-list-of-modules-with-parenthesis/77001/12 "2025-01-16T13:44:13Z")

</div>

Yes, being able to write imports this way seens nice enough.  
Importing a tuple doesn’t make sense anyway, so there is no syntax ambiguity or conflict.
