Q:

Ignore flake8 check for the code with backslash

Is there a way to ignore flake8 check for a part of code with \? I cannot add #noqa after \.
For example, here is the code I have. .config('spark.driver.maxResultSize', os.getenv('spark_driver_max_result_size')) \ is over 79 characters
session = SparkSession \
    .builder \
    .appName(os.getenv('app_name')) \
    .config('spark.yarn.queue', os.getenv('spark_yarn_queue')) \
    .config('spark.driver.memory', os.getenv('spark_driver_memory')) \
    .config('spark.executor.memory', os.getenv('spark_executor_memory')) \
    .config('spark.driver.maxResultSize', os.getenv('spark_driver_max_result_size')) \
    .enableHiveSupport() \
    .getOrCreate()

This would not work.
session = SparkSession \
    .builder \
    .appName(os.getenv('app_name')) \
    .config('spark.yarn.queue', os.getenv('spark_yarn_queue')) \
    .config('spark.driver.memory', os.getenv('spark_driver_memory')) \
    .config('spark.executor.memory', os.getenv('spark_executor_memory')) \
    .config('spark.driver.maxResultSize', os.getenv('spark_driver_max_result_size')) \  # noqa: E501
    .enableHiveSupport() \
    .getOrCreate()

A:

You can wrap you expression in parentheses, and then use newlines normally in those parentheses
session = (SparkSession 
    .builder 
    .appName(os.getenv('app_name')) 
    .config('spark.yarn.queue', os.getenv('spark_yarn_queue')) 
    .config('spark.driver.memory', os.getenv('spark_driver_memory')) 
    .config('spark.executor.memory', os.getenv('spark_executor_memory')) 
    .config('spark.driver.maxResultSize', os.getenv('spark_driver_max_result_size')) # noqa: E501
    .enableHiveSupport()
    .getOrCreate())

