c40cd09e3906 — David Keijser 4 years ago
Add type annotations to public facing API

The PEP561 marker lets dependent projects using mypy type check code using this
module.
3 files changed, 10 insertions(+), 9 deletions(-)

M scfg/__init__.py
A => scfg/py.typed
M setup.py
M scfg/__init__.py +8 -7
@@ 1,4 1,5 @@ 
 import shlex
+from typing import List, Dict, Optional
 
 
 def get(directives, name):

          
@@ 16,9 17,9 @@ def get_all(directives, name):
 
 
 class Directive:
-    name = None
-    params = None
-    children = None
+    name: str
+    params: List[str]
+    children: List['Directive']
 
     def __init__(self, name, params, children=None):
         self.name = name

          
@@ 28,10 29,10 @@ class Directive:
     def __str__(self):
         return f"{self.name}: {self.params}"
 
-    def get(self, name):
+    def get(self, name) -> Optional['Directive']:
         return get(self.children, name)
 
-    def get_all(self, name):
+    def get_all(self, name) -> List['Directive']:
         return get_all(self.children, name)
 
 

          
@@ 84,8 85,8 @@ class Config:
 
         return blocks, closing_brace
 
-    def get(self, name):
+    def get(self, name) -> Optional[Directive]:
         return get(self.directives, name)
 
-    def get_all(self, name):
+    def get_all(self, name) -> List[Directive]:
         return get_all(self.directives, name)

          
A => scfg/py.typed +1 -0
@@ 0,0 1,1 @@ 
+# Marker file for PEP 561.

          
M setup.py +1 -2
@@ 9,11 9,11 @@ else:
         "See https://hg.code.netlandish.com/~petersanchez/py-scfg"
     )
 
-
 setup(
     name="py-scfg",
     version="0.1.1",
     packages=find_packages(),
+    package_data={"scfg": ["py.typed"]},
     description="Module to read scfg formatted configuration files.",
     author="Peter Sanchez",
     author_email="pjs@petersanchez.com",

          
@@ 30,5 30,4 @@ setup(
         "Programming Language :: Python :: 3.7",
         "Programming Language :: Python :: 3.8",
     ],
-    include_package_data=True,
 )