How to suppress syntax checking in PyCharm?

I am using PyCharm 3.4.1, and I have this piece of code in my function:

cursor.execute('SELECT distinct "name_{0}", code, sort_order FROM {1}'.format(get_language(), ProgrammeLevel._meta.db_table)) 

PyCharm correctly recognizes that the string contains SQL code, but checking the syntax of the code tells me that I have a syntax error due to FROM {1} , it says: <comma join expression> expected, got '{' , which is a valid point but I know what I'm doing.

For most, if not all PyCharm checks, I can write a # noinspection in the right place and disable the check for some piece of code. I did this to disable the PyProtectedMember check for the code snippet I just gave. How to disable syntax checking for this line of code? What name should be provided in the noinspection comment?

+6
source share
1 answer

This is controlled by language injections, not checks.

To suppress an error:
SettingsEditorLanguage Injections and uncheck the box that says:
python:"SQL select/delete/insert/update/create"

Language injections


Or, to disable it only in lines with { } , change the very end of the Places Pattern from .* To [^{}]* like this:

 + pyStringLiteralMatches("[ \\t\\r\\n]*(((SELECT|DELETE) .*FROM)|((INSERT|REPLACE) .*INTO)|(UPDATE .* SET)|((CREATE|DROP|ALTER) +(TABLE|INDEX))).*") 

For this:

 + pyStringLiteralMatches("[ \\t\\r\\n]*(((SELECT|DELETE) .*FROM)|((INSERT|REPLACE) .*INTO)|(UPDATE .* SET)|((CREATE|DROP|ALTER) +(TABLE|INDEX)))[^{}]*") 

pyStringLiteralMatches

+8
source

Source: https://habr.com/ru/post/974210/


All Articles