How to suppress syntax inspection in PyCharm?
Asked Answered
T

1

6

I'm 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 the code syntax inspection informs me that I have a syntax error because of 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 inspections I can write a # noinspection comment in the right place and turn the inspection off for some piece of code. I did so, to turn off the PyProtectedMember inspection for the code snippet I just gave. How can I turn off the syntax inspection for this line of code? What is the inspection name to give to noinspection comment?

Topo answered 22/8, 2014 at 10:54 Comment(0)
H
10

This is controlled with language injections rather than inspections.

To suppress the error:
Settings -> Editor -> Language Injections and uncheck the box that says:
python:"SQL select/delete/insert/update/create"

Language Injections


Or, to only disable it on strings with {} in them, change the very end of the Places Pattern from .* to [^{}]* like so:

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

To this:

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

pyStringLiteralMatches

Holophrastic answered 2/7, 2015 at 16:19 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.