0

My package structure looks like this

mypackage
│   LICENSE
│   pyproject.toml
│   README.md
│   requiremets.txt            
├───docs
├───scripts          
├───src
│   └───mypackage
│          config.py
│          first_module.py
│          second_module.py
│          __init__.py         
└───tests

the content of my __init__.py is this

from .first_module import *  # NOQA
from .second_module import *  # NOQA

and in second_module.py I have the following

from .first_module import *  # NOQA analysis:ignore

I run pip install -e . to have my package in the right place while developing.

My second_module.py is full of these warnings

'myfunction' may be undefined, or defined in star imports .first_module (pyflakes E)

and these errors

'MY_CONST' is not defined (mypy)

How to disable such warnings/errors? If it may be useful, I am using the following IDE

* Spyder version: 5.2.2 None
* Python version: 3.9.12 64-bit
* Qt version: 5.9.7
* PyQt5 version: 5.9.2
* Operating System: Windows 10

I have found similar questions here and here and I am aware that star imports shall be avoided, but I also read that when developing a package with the described structure (which is one of the recommended btw), then using star imports in such a specific manner is the way to go.

EDIT: I found a way for circumnavigating it and it is to add a # noqa at the end of each line where I get the warning. But that happens on a tons of lines and it is very annoying to fix the code in this way.

EDIT 2: I have tried to create a ~/.flake8 file with the following content

[flake8]
extend-ignore = F403,F405

But it didn't work. I also tried replacing extend-ignore with ignore but I got the same result.

EDIT 3: I observed that by having the aforementioned .flake8 file in my project root folder and by running flake8.exe ./src/mypackage/first_module.py, then F405 is correctly ignored, but running pyflakes.exe ./src/mypackage/first_module.py the F405 warning is still there. Hence, once shall tell pyflakes to add extend-ignore = F403,F405 to its flake8 config file, but is not possible since pyflakes does not use any config file..

Barzi2001
  • 989
  • 8
  • 24
  • As the warning says, it comes from`pyflakes`. I suggest you google "python pyflakes" to find the documentation about how to configure it. – Code-Apprentice Sep 09 '22 at 14:43
  • I got it. And the answer is that `pyflakes` cannot be configured. So there appear to be no solution to my problem as-is in Spyder. I raised an issue in their issue tracker. Nevertheless, I could use `flake8` externally. – Barzi2001 Sep 10 '22 at 20:01

1 Answers1

0

Hi If you want to import your first module to second then use

from .first_module import * instead of from .first_module *

also in your terminal invoke python and then check whether you have pyflakes installed if not then install it using below command

pip install pyflakes

Hope it helps as per the error shared by you.

amnpawar
  • 104
  • 7
  • Actually I mistakenly copied/pasted. Edited. I have pyflakes installed (otherwise I would not get any error). – Barzi2001 Sep 09 '22 at 15:29
  • Then i would recommend you better go with the best approach of importing the modules or libraries you require to be used. You can also check Flake8 rules in below [link](https://www.flake8rules.com/rules/F405.html) – amnpawar Sep 09 '22 at 16:04