diff options
| author | jvoisin | 2018-04-02 19:11:59 +0200 |
|---|---|---|
| committer | jvoisin | 2018-04-02 19:11:59 +0200 |
| commit | 23bd22b30548e7ab83bfe81abd666bfac2a77712 (patch) | |
| tree | 57895b4a2650a16b5b1c03422b418e785efe52cf /src/parser_factory.py | |
| parent | 6868f20065ef2e46f295c34f27c0736d54283535 (diff) | |
Add more typing hints
Diffstat (limited to 'src/parser_factory.py')
| -rw-r--r-- | src/parser_factory.py | 7 |
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 | ||
| 5 | from . import abstract | 5 | from . import abstract |
| 6 | 6 | ||
| 7 | from typing import Type, TypeVar | ||
| 8 | |||
| 9 | T = TypeVar('T', bound='abstract.AbstractParser') | ||
| 10 | |||
| 7 | for module_loader, name, ispkg in pkgutil.walk_packages('.src'): | 11 | for 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 | ||
| 14 | def get_parser(filename: str): | 18 | def 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 |
