Unwanted __init__.py being generated when moving scripts
已回答
Steps to reproduce:
- Create an empty Python project
- Create a directory (not a package)
- Create a Python file
- Move the file into the directory
A
__init__.py
file will be created in the directory.
How can I disable this behavior?
请先登录再写评论。
Hi Claas Meiners! Disable Search for references option in move window:
Just a note that if you use a pip namespace https://packaging.python.org/en/latest/guides/packaging-namespace-packages/
Then moving a file within your sub package will add a __init__.py file to the namespace which will cause interference with the installed namespace in the virtualenv.
I don't think intellij should be adding __init__.py files for pre-existing folders, it's okay if the move creates folders though.
I am having the same issue and it is frustrating. Pycharm should not be adding an __init__.py file to a namespace package. Disabling "Search for reference" is not a good solution either because we typically want references to be updated.
Agreed, Pavel's solution above is like killing the patient to cure the cancer
Hey, is there a solution for this instead of disabling the "Search for reference"?
Honestly, this is the type of stuff that makes me want to move to vim. This should 1000% be configurable as a setting and its incredibly debatable whether this should be a default. It is extremely easy to miss this and then all of a sudden you recursively have delete these unwanted files…
Still no update? And why is this marked as `Answered`?
This hasn't been answered or fixed.
It's 2024 and we dont need __init__.py any more. Do not create these files! This should be such an easy fix, dissapointing no one has taken care of it already.
Still a damn problem. Very frustrating. Moving to VisualCode
Hugely frustrating that PyCharm 2024.3.5 still doesn't respect namespace packages. Even though namespace packages are marked as such in my project, every Move refactoring recreates unwanted __init__.py files which stop name resolution working properly across the whole project. I have to remember to remove these __init__.py files every time.
Robert Smallshire, this appears to be related to PY-44858, although it was expected to be resolved in the 2024.3.5 release.
Please consider upvoting and watching the issue to stay informed about any updates.
If you're not familiar with YouTrack, you can refer to this article for guidance on how to interact with it.