Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check fails for submodules #1

Open
m-aciek opened this issue Apr 10, 2019 · 2 comments
Open

Check fails for submodules #1

m-aciek opened this issue Apr 10, 2019 · 2 comments

Comments

@m-aciek
Copy link

m-aciek commented Apr 10, 2019

Current behaviour:

$ cat positive.py 
from collections.abc import Container

Container()
$ flake8 positive.py 
positive.py:1:1: I801 use 'import collections.abc' instead of 'from collections.abc import Container'
$
$ cat false-positive.py 
from collections import abc

abc.Container()
$ flake8 false-positive.py 
false-positive.py:1:1: I801 use 'import collections' instead of 'from collections import abc'
$
$ cat negative.py 
import collections

collections.abc.Container()
$ flake8 negative.py 
$ 

Checks should pass for second file, shouldn't they?

@sfstpala
Copy link
Owner

sfstpala commented Apr 10, 2019

No, it actually wants you to type import collections.abc instead of from collections import abc.

I see where you're coming from, and it makes sense. Maybe it should be an option at least. The convention that birthed this module was basically to never use from at all, wether you're importing a module or another object.

However, the error message is definitely wrong. It should say use 'import collections.abc' instead of 'from collections import abc'

@mnowotka
Copy link

Ability to configure the project and relax some constraints would be super useful!

ericbn added a commit to ericbn/flake8-import-style that referenced this issue Mar 27, 2022
Since relative imports don't work with the `import <>` syntax, suggest
importing the names directly. In this cases, the `i.module` is `None`
and the `i.level` has the number of levels down in the relative import,
e.g. `1` means the current directory.

If there's only one name, suggest:

    use 'import module.name' instead of 'from module import name'

This implements the enhancement proposed in sfstpala#1.
ericbn added a commit to ericbn/flake8-import-style that referenced this issue Mar 27, 2022
Since relative imports don't work with the `import <>` syntax, suggest
importing the names directly. In these cases, the `i.module` is `None`
and the `i.level` has the number of levels down in the relative import,
e.g. `1` means the current directory.

If there's only one name, suggest:

    use 'import module.name' instead of 'from module import name'

This implements the enhancement proposed in sfstpala#1.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants