hhatto / autopep8

A tool that automatically formats Python code to conform to the PEP 8 style guide.
https://pypi.org/project/autopep8/
MIT License
4.54k stars 291 forks source link

fixer for E1,W191 causes E122,E123 or E126 #668

Open spaceone opened 1 year ago

spaceone commented 1 year ago

The following code (indented with tabs):

def foo(openapi_schemas):
    openapi_schemas[f'{model_name}.response-mixin'] = {
        "type": "object",
        "properties": {
            "_links": {
                "$ref": '#/components/schemas/_links',
            },
            "_embedded": {
                "$ref": '#/components/schemas/_embedded',
            },
            "uuid": {
                "$ref": '#/components/schemas/uuid',
            },
            "objectType": {
                "$ref": '#/components/schemas/objectType',
            },
            # "id": {"$ref": '#/components/schemas/id',},
            "uri": {
                "$ref": f'#/components/schemas/{_openapi_quote(model_name + ".uri")}',
            },
        },
    }

will be transformed incorrectly (without specifying args or with --select E1,W191) into:

def foo(openapi_schemas):
    openapi_schemas[f'{model_name}.response-mixin'] = {
        "type": "object",
        "properties": {
                "_links": {
                    "$ref": '#/components/schemas/_links',
                },
            "_embedded": {
                    "$ref": '#/components/schemas/_embedded',
                },
            "uuid": {
                    "$ref": '#/components/schemas/uuid',
            },
            "objectType": {
                    "$ref": '#/components/schemas/objectType',
            },
            # "id": {"$ref": '#/components/schemas/id',},
            "uri": {
                    "$ref": f'#/components/schemas/{_openapi_quote(model_name + ".uri")}',
            },
        },
    }

causing therefore

foo.py:13:13: E122 continuation line missing indentation or outdented
foo.py:16:13: E122 continuation line missing indentation or outdented

When specifying --select E101,W191 it looks better but it's indented with 8 spaces instead of 4 causing:

bar.py:3:13: E126 continuation line over-indented for hanging indent
bar.py:6:29: E126 continuation line over-indented for hanging indent
bar.py:8:21: E126 continuation line over-indented for hanging indent
bar.py:9:29: E126 continuation line over-indented for hanging indent
bar.py:12:29: E126 continuation line over-indented for hanging indent
bar.py:15:29: E126 continuation line over-indented for hanging indent
bar.py:19:29: E126 continuation line over-indented for hanging indent

with --ignore E122 --hang-closing it's completely broken and the } are not indented anymore at all.