grantjenks / blue

The slightly less uncompromising Python code formatter.
https://blue.readthedocs.io/
Other
393 stars 21 forks source link

error: cannot format main.py: Cannot parse: 66:21 #105

Closed hastyulia closed 5 months ago

hastyulia commented 5 months ago

Hello, I got an error:

error: cannot format app/logic/shparsing/validators.py: Cannot parse: 66:21:         
return Union[*[types_mapping.get(type_['type'])(json_schema) for type_ in any_of]] 

Code:

def json_schema_to_pydantic_type(json_schema: dict[str, Any]) -> Any:
    if any_of := json_schema.get('anyOf', []):
        return Union[*[types_mapping.get(type_['type'])(json_schema) for type_ in any_of]]
    type_ = json_schema.get('type')
    mapped = types_mapping.get(type_)(json_schema)
    if not mapped:
        raise ValueError(f'Unsupported JSON schema type: {type_}')
    return mapped

I found a solution with # fmt: off and # fmt: on, but are there any other ways to fix it? Because this way doesn't work.

hastyulia commented 5 months ago

I found solution with using tuple: return Union[tuple(types_mapping.get(type_['type'])(json_schema) for type_ in any_of)]