Skip to content

Commit 51ffdfa

Browse files
authored
Add typing (#59)
1 parent 2541004 commit 51ffdfa

File tree

6 files changed

+50
-10
lines changed

6 files changed

+50
-10
lines changed

.github/workflows/dists.yml

+7-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,13 @@
33
# Publish runs only on a tag push
44
name: Dists
55

6-
on: [push, pull_request]
6+
on:
7+
push:
8+
branches:
9+
- master
10+
pull_request:
11+
branches:
12+
- master
713

814
jobs:
915
build:
@@ -78,7 +84,6 @@ jobs:
7884
with:
7985
python-version: 3.9
8086

81-
8287
- name: Build sdist
8388
run: |
8489
./setup.py sdist

MANIFEST.in

+1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
1+
global-include *.pyi
12
recursive-include include *
23
recursive-include third_party *

setup.cfg

+3
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,7 @@ package_dir = =src
3535
[options.packages.find]
3636
where = src
3737

38+
[options.package_data]
39+
* = *.pyi
40+
3841
[tool:pytest]

src/pytomlpp/__init__.py

+2-6
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,5 @@
22

33
__all__ = ["DecodeError", "dumps", "loads", "dump", "load"]
44

5-
from ._impl import DecodeError
6-
from ._impl import dumps
7-
from ._impl import loads
8-
from ._impl import lib_version
9-
from ._io import dump
10-
from ._io import load
5+
from ._impl import DecodeError, lib_version
6+
from ._io import dump, dumps, load, loads

src/pytomlpp/_impl.pyi

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
2+
lib_version: str = ...
3+
4+
5+
class DecodeError(Exception):
6+
"""Error raised when decoding fails."""
7+
...

src/pytomlpp/_io.py

+30-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,26 @@
11
"""Python wrapper for Toml++ IO methods."""
22

3+
import os
4+
from typing import Any, BinaryIO, Dict, TextIO, Union
5+
36
from . import _impl
47

8+
FilePathOrObject = Union[str, TextIO, BinaryIO, os.PathLike]
9+
10+
11+
def dumps(data: Dict[Any, Any]) -> str:
12+
"""Serialise data to TOML as string.
13+
14+
Args:
15+
data: data to serialise
16+
17+
Returns:
18+
serialised data
19+
"""
20+
return _impl.dumps(data)
21+
522

6-
def dump(data, fl, mode="w"):
23+
def dump(data: Dict[Any, Any], fl: FilePathOrObject, mode: str = "w") -> None:
724
"""Serialise data to TOML.
825
926
Args:
@@ -24,8 +41,19 @@ def dump(data, fl, mode="w"):
2441
fh.write(data)
2542

2643

44+
def loads(data: str) -> Dict[Any, Any]:
45+
"""Deserialise from TOML as dictionary.
46+
47+
Args:
48+
data (str): data to deserialise
49+
50+
Returns:
51+
deserialised data
52+
"""
53+
return _impl.loads(data)
54+
2755

28-
def load(fl, mode="r"):
56+
def load(fl: FilePathOrObject, mode: str = "r") -> Dict[Any, Any]:
2957
"""Deserialise from TOML.
3058
3159
Args:

0 commit comments

Comments
 (0)