summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorjvoisin2018-04-02 19:11:59 +0200
committerjvoisin2018-04-02 19:11:59 +0200
commit23bd22b30548e7ab83bfe81abd666bfac2a77712 (patch)
tree57895b4a2650a16b5b1c03422b418e785efe52cf /src
parent6868f20065ef2e46f295c34f27c0736d54283535 (diff)
Add more typing hints
Diffstat (limited to 'src')
-rw-r--r--src/parser_factory.py7
1 files changed, 5 insertions, 2 deletions
diff --git a/src/parser_factory.py b/src/parser_factory.py
index 226234b..812d95c 100644
--- a/src/parser_factory.py
+++ b/src/parser_factory.py
@@ -4,6 +4,10 @@ import pkgutil
4 4
5from . import abstract 5from . import abstract
6 6
7from typing import Type, TypeVar
8
9T = TypeVar('T', bound='abstract.AbstractParser')
10
7for module_loader, name, ispkg in pkgutil.walk_packages('.src'): 11for module_loader, name, ispkg in pkgutil.walk_packages('.src'):
8 if not name.startswith('src.'): 12 if not name.startswith('src.'):
9 continue 13 continue
@@ -11,10 +15,9 @@ for module_loader, name, ispkg in pkgutil.walk_packages('.src'):
11 continue 15 continue
12 importlib.import_module(name) 16 importlib.import_module(name)
13 17
14def get_parser(filename: str): 18def get_parser(filename: str) -> (T, str):
15 mtype, _ = mimetypes.guess_type(filename) 19 mtype, _ = mimetypes.guess_type(filename)
16 for c in abstract.AbstractParser.__subclasses__(): 20 for c in abstract.AbstractParser.__subclasses__():
17 if mtype in c.mimetypes: 21 if mtype in c.mimetypes:
18 return c(filename), mtype 22 return c(filename), mtype
19 print('factory: %s is not supported' % mtype)
20 return None, mtype 23 return None, mtype