Skip to content

Commit a126b97

Browse files
committed
Add type stubs and improve annotations
1 parent e922062 commit a126b97

File tree

2 files changed

+9
-7
lines changed

2 files changed

+9
-7
lines changed

azure/functions/_json.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
# Licensed under the MIT License.
33

44
from enum import Enum
5+
from typing import AnyStr, Any
56
import os
67

78
AZUREFUNCTIONS_UJSON_ENV_VAR = 'AZUREFUNCTIONS_UJSON'
@@ -40,21 +41,21 @@ def default(self, o):
4041
JSONDecodeError = json.JSONDecodeError
4142

4243
if HAS_UJSON:
43-
def dumps(v, **kwargs):
44+
def dumps(v: Any, **kwargs) -> str:
4445
if 'default' in kwargs:
4546
return json.dumps(v, **kwargs)
4647

4748
if 'cls' in kwargs:
4849
del kwargs['cls']
49-
50+
5051
return ujson.dumps(v, **kwargs)
5152

52-
def loads(*args, **kwargs):
53+
def loads(s: AnyStr, **kwargs):
5354
if kwargs:
54-
return json.loads(*args, **kwargs)
55+
return json.loads(s, **kwargs)
5556
else: # ujson takes no kwargs
56-
return ujson.loads(*args)
57+
return ujson.loads(s)
5758

5859
else:
59-
dumps = json.dumps
60+
dumps = json.dumps # type: ignore
6061
loads = json.loads

setup.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@
1212
'pytest-cov',
1313
'pytest-benchmark',
1414
'requests==2.*',
15-
'coverage'
15+
'coverage',
16+
'types-ujson'
1617
],
1718
'ujson': ['ujson>=5.3.0,<6.0']
1819
}

0 commit comments

Comments
 (0)