I created a text file, and renamed it into testTreeGen.py.
The problem
I cannot say for sure what mistake you've made, however, this is the way to properly rename a file:
If the above fails for whatever reason, try the following, otherwise this is bug that you need to report:
I deleted the the .idea
folder, I cleared the cache using the File-> Invalidate Chache
menu option, I deleted the __pycache__
folders. I also tried to check out a new version into a new folder as well as copy and pasted the relevant files into a new folder.
None of the solutions worked so it seems that if you declare the file wrongly it is globally registered in all projects as this wrong file type.
I just reinstalled PyCharm deleting all settings. However, if I would have had more custom plugs-ins or settings, I would have started playing with the global pycharm settings rather than the project settings. One option might be deleting the C:\User\<username>\.PyCharm<version>
folder which should contain the config, this resetting your PyCharm to factory settings. Obviously do not want to replicate the error now.
My short version: The file type is not saved in the project folder so if you do not find a menu option to change it, go and play with the global settings which are saved in the in the folder mentioned above.
Go in the Settings -->Editor --> File Types --> Text --> Registered Patterns (lower list box in the dialog) --> Remove the file name that has been added (Should be the file name you accidentally created as text file) by clicking the "-" right hand side. Apply and you should have this speeding ticket off your record.
Settings (Preferences on Mac) | Editor | File Types | Text
Check patterns there (bottom list) -- you must have had testTreeGen
or similar pattern. Just remove it.
This usually happens when creating new file and instead of using specific file template you use New | File
and forgetting to enter file extension (which is required here as opposed to specific file template which adds file extension automatically) -- this is to allow to create ANY file with any extension (e.g. .htaccess
or just README
).
Since such file (testTreeGen
in your case) does not have extension, IDE does not know how to treat it and treats it as plain text (not automatically though -- it asking you to choose correct file type with "text file" type preselected, but vast majority of users just hitting enter instead of reading what that screen says -- "relax, I'm a professional and I know what I'm doing").
Now, since the testTreeGen
pattern is there and it is bigger/more precise that generic *.rb
or *.py
, file is treated as Text file regardless of file extension -- renaming will not help.
Conclusion / advice -- pay a bit more attention to confirmation dialogs.