Why does PyCharm say "Typo in word"? [SOLVED]

Why does PyCharm say " typo in word 'txtfile' " in the statement that defines the variable 'txtfile'?

 

1

Hello, 

 

The  Typo inspection defined 'txtfile' as not included in any dictionary. You can add this word to a dictionary and it will be skipped by the spellchecker in the future.  Please see https://www.jetbrains.com/help/pycharm/spellchecking.html

 

 

1

Does variable names of the type file have to conform to a dictionary?

0

Yes, if you would like it not to be marked as "typo" . 

1

Why do variables of the type 'file' have to conform to a dictionary, when all the other variable types can have whatever name you wish?

0

Hello Hendrik, 

 

`txtfile`  is not a commonly known word that could exist in a dictionary.  There are 2 dictionaries used for spellchecking: general(https://github.com/JetBrains/intellij-community/blob/9612562bf2d55cb551126cd3e55fdff1029c4c86/spellchecker/src/com/intellij/spellchecker/english.dic)  and for Python(https://github.com/JetBrains/intellij-community/blob/4999f5293e4307870020f1d0d672a3d35a52f22d/python/src/com/jetbrains/python/spellchecker/python.dic)

If a word is split, for example, by '_' sign, there is an additional logic that skips such cases from checking.    

 

1

But why do variable names of certain variable types have to conform to a dictionary?

0

The spellcheking does not rely on variable type,  it should be performed for the whole code. 

So you mean that if "txtfile" variable has a different type then it will not be marked as "typo"? Please provide me with a real example.  

2

I am sorry, I haven't checked this before! 'txtfile' is still marked as a typo in this statement:

txtfile = 234

But 'txt_file' is accepted. I am just not used to IDEs that check the spelling of variable names! :-)

0

It is absolutely NOT true that all source code should be checked. 

Fortunately, you can configure this in the IDE in Settings -> Editor -> Inspections -> Proofreading -> Typo. 
(Or search "Proofreading" after opening settings). 

I find a good compromise is to only check comments.  This still flags, for example, closing comments on header guards, which is problematic, but it reduces the list a lot. 

1

Thanks for your excellent feedback Stephen Schilz!!

0

请先登录再写评论。