Skip to content

Commit 3757d7d

Browse files
committed
add a tiny bit of type checking
1 parent 043f802 commit 3757d7d

File tree

1 file changed

+6
-7
lines changed

1 file changed

+6
-7
lines changed

src/pyff/utils.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,12 @@
2424
from itertools import chain
2525
from threading import local
2626
from time import gmtime, strftime
27+
from typing import AnyStr, Optional, Union
2728

2829
import iso8601
2930
import pkg_resources
3031
import requests
31-
import six
3232
import xmlsec
33-
import yaml
3433
from _collections_abc import Mapping, MutableMapping
3534
from apscheduler.executors.pool import ThreadPoolExecutor
3635
from apscheduler.jobstores.memory import MemoryJobStore
@@ -43,7 +42,7 @@
4342
from requests.structures import CaseInsensitiveDict
4443
from requests_cache import CachedSession
4544
from requests_file import FileAdapter
46-
from six.moves.urllib_parse import quote_plus, urlparse
45+
from six.moves.urllib_parse import urlparse
4746

4847
from . import __version__
4948
from .constants import NS, config
@@ -720,21 +719,21 @@ def url_get(url):
720719
return r
721720

722721

723-
def safe_b64e(data):
724-
if not isinstance(data, six.binary_type):
722+
def safe_b64e(data: Union[str, bytes]) -> str:
723+
if not isinstance(data, bytes):
725724
data = data.encode("utf-8")
726725
return base64.b64encode(data).decode('ascii')
727726

728727

729-
def safe_b64d(s):
728+
def safe_b64d(s: str) -> bytes:
730729
return base64.b64decode(s)
731730

732731

733732
# data:<class 'type'>;base64,
734733
# data:<class 'type'>;base64,
735734

736735

737-
def img_to_data(data, content_type):
736+
def img_to_data(data: bytes, content_type: str) -> Optional[str]:
738737
"""Convert a file (specified by a path) into a data URI."""
739738
mime_type, options = cgi.parse_header(content_type)
740739
data64 = None

0 commit comments

Comments
 (0)