Apply black to all python files (bfxapi/**/*.py).

This commit is contained in:
Davide Casale
2024-02-26 19:43:14 +01:00
parent 2b7dfc5b8a
commit 38dbff1141
33 changed files with 1843 additions and 1335 deletions

View File

@@ -2,15 +2,16 @@ import json
from decimal import Decimal
from typing import Any, Dict, List, Union
_ExtJSON = Union[Dict[str, "_ExtJSON"], List["_ExtJSON"], \
bool, int, float, str, Decimal, None]
_ExtJSON = Union[
Dict[str, "_ExtJSON"], List["_ExtJSON"], bool, int, float, str, Decimal, None
]
_StrictJSON = Union[Dict[str, "_StrictJSON"], List["_StrictJSON"], int, str, None]
_StrictJSON = Union[Dict[str, "_StrictJSON"], List["_StrictJSON"], \
int, str, None]
def _clear(dictionary: Dict[str, Any]) -> Dict[str, Any]:
return { key: value for key, value in dictionary.items() \
if value is not None }
return {key: value for key, value in dictionary.items() if value is not None}
def _adapter(data: _ExtJSON) -> _StrictJSON:
if isinstance(data, bool):
@@ -21,12 +22,13 @@ def _adapter(data: _ExtJSON) -> _StrictJSON:
return format(data, "f")
if isinstance(data, list):
return [ _adapter(sub_data) for sub_data in data ]
return [_adapter(sub_data) for sub_data in data]
if isinstance(data, dict):
return _clear({ key: _adapter(value) for key, value in data.items() })
return _clear({key: _adapter(value) for key, value in data.items()})
return data
class JSONEncoder(json.JSONEncoder):
def encode(self, o: _ExtJSON) -> str:
return super().encode(_adapter(o))