1
0
mirror of synced 2024-11-22 01:04:23 +01:00

Add more typing hints

This commit is contained in:
jvoisin 2018-04-02 19:11:59 +02:00
parent 6868f20065
commit 23bd22b305

View File

@ -4,6 +4,10 @@ import pkgutil
from . import abstract
from typing import Type, TypeVar
T = TypeVar('T', bound='abstract.AbstractParser')
for module_loader, name, ispkg in pkgutil.walk_packages('.src'):
if not name.startswith('src.'):
continue
@ -11,10 +15,9 @@ for module_loader, name, ispkg in pkgutil.walk_packages('.src'):
continue
importlib.import_module(name)
def get_parser(filename: str):
def get_parser(filename: str) -> (T, str):
mtype, _ = mimetypes.guess_type(filename)
for c in abstract.AbstractParser.__subclasses__():
if mtype in c.mimetypes:
return c(filename), mtype
print('factory: %s is not supported' % mtype)
return None, mtype