I had to disable the format on save setting, because Python PEP8 Autoformat plugin reformatted my code, causing a syntax error.
My code (focus on last lines):
from typing import List, Tuple
from my_enent import MyEvent
def my_preprocessor(raw_event, context: object, env: MyEnv) \
-> Tuple[dict, VideoFreezeEvent]:
if isinstance(raw_event, dict) and 'Output' in raw_event:
# comments
raw_state_machine_event = json.loads(raw_state_machine_event['Output'])
# comments
parallel_outputs = raw_state_machine_event.get(
'my_data').get('parallel_outputs')
if len(parallel_outputs) > 0:
state_machine_event = parallel_outputs[0]
my_list: List[MyEvent] = [
my_util.populate_dataclass(MyEvent, event)
for event in parallel_outputs
]
another_event = events_list[0]
After the plugin reformats the code, the relevant part of the code that causes the syntax error becomes:
if len(parallel_outputs) > 0:
state_machine_event = parallel_outputs[0]
my_list:
List[MyEvent] = [
my_util.populate_dataclass(MyEvent, event)
for event in parallel_outputs
]
another_event = events_list[0]
How can I prevent/teach the plugin to not break this code please?
Some package settings that might be the way through, if a passage exists in the first place:
{
// list codes for fixes; used by --ignore and --select
"list-fixes": false,
// do not fix these errors / warnings (e.g. [ "E501" , "E4" , "W"])
"ignore": [],
// select errors / warnings (e.g. ["E4", "W"])
"select": [],
// Maximum line length
"max-line-length": 79
}