Search code examples
pythonf-string

How to fix SyntaxError: f-string: expressions nested too deeply in python 3.7.0?


Below is my code snippet. When running the code in python 3.7 I get the error SyntaxError: f-string: expressions nested too deeply. How should I refactor my code?

    GRAPH_QL_FIELDS = """
                cubeId
                title
                deleted
                timeVariableFormat
                statisticalProgram {
                  name
                }
                topics{
                    topicId
                }
              }
    """

    query_topics = (
                f'query cubesWithTopicLink($deleted: Boolean!, $topicId: String, $first: Int, $skip: Int) {{'
                f'dataCubes(where:{AND:[{topics_some: {{topicId: $topicId}}}, {deleted: $deleted}]}, first: $first, skip: $skip) {{'
                f'{GRAPH_QL_FIELDS}'
                f'dataCubesConnection(where: {topics_some: {topicId: $topicId}})'
                f'{{aggregate{{count}}}}'
                f'}}'
            )

Solution

  • You could use multi-line strings f"""This will work as expected with other nested strings '{3+5}'"""