mirror of
https://github.com/aiogram/aiogram.git
synced 2025-12-11 18:01:04 +00:00
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.
26 lines
378 B
Python
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)
|