aiogram/aiogram/utils/json.py
Oleg A a06cdd188d
Update json.py
fix pyCharm warning
'ujson' in try block with 'except ImportError' should also be defined in except block
This inspection detects names that should resolve but don't. Due to dynamic dispatch and duck typing, this is possible in a limited but useful number of cases. Top-level and class-level items are supported better than instance items.
2018-07-21 11:31:18 +03:00

26 lines
378 B
Python

import json
try:
import ujson
except ImportError:
ujson = None
_use_ujson = True if ujson else False
def disable_ujson():
global _use_ujson
_use_ujson = False
def dumps(data):
if _use_ujson:
return ujson.dumps(data)
return json.dumps(data)
def loads(data):
if _use_ujson:
return ujson.loads(data)
return json.loads(data)