Skip to content

Commit

Permalink
Merge e509082 into 73124de
Browse files Browse the repository at this point in the history
  • Loading branch information
techalchemy committed May 16, 2019
2 parents 73124de + e509082 commit 6baea81
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 10 deletions.
5 changes: 4 additions & 1 deletion src/dotenv/__init__.py
@@ -1,6 +1,9 @@
from typing import Any, Optional
from .compat import IS_TYPE_CHECKING
from .main import load_dotenv, get_key, set_key, unset_key, find_dotenv, dotenv_values

if IS_TYPE_CHECKING:
from typing import Any, Optional


def load_ipython_extension(ipython):
# type: (Any) -> None
Expand Down
5 changes: 4 additions & 1 deletion src/dotenv/cli.py
@@ -1,6 +1,5 @@
import os
import sys
from typing import Any, List

try:
import click
Expand All @@ -9,9 +8,13 @@
'Run pip install "python-dotenv[cli]" to fix this.')
sys.exit(1)

from .compat import IS_TYPE_CHECKING
from .main import dotenv_values, get_key, set_key, unset_key, run_command
from .version import __version__

if IS_TYPE_CHECKING:
from typing import Any, List


@click.group()
@click.option('-f', '--file', default=os.path.join(os.getcwd(), '.env'),
Expand Down
13 changes: 13 additions & 0 deletions src/dotenv/compat.py
@@ -1,3 +1,4 @@
import os
import sys

if sys.version_info >= (3, 0):
Expand All @@ -6,3 +7,15 @@
from StringIO import StringIO # noqa

PY2 = sys.version_info[0] == 2 # type: bool


def is_type_checking():
# type: () -> bool
try:
from typing import TYPE_CHECKING
except ImportError:
return False
return TYPE_CHECKING


IS_TYPE_CHECKING = os.environ.get("MYPY_RUNNING", is_type_checking())
22 changes: 14 additions & 8 deletions src/dotenv/main.py
Expand Up @@ -9,15 +9,17 @@
import sys
from subprocess import Popen
import tempfile
from typing import (Any, Dict, Iterator, List, Match, NamedTuple, Optional, # noqa
Pattern, Union, TYPE_CHECKING, Text, IO, Tuple) # noqa
import warnings
from collections import OrderedDict
from contextlib import contextmanager

from .compat import StringIO, PY2
from .compat import StringIO, PY2, IS_TYPE_CHECKING

if TYPE_CHECKING: # pragma: no cover
if IS_TYPE_CHECKING: # pragma: no cover
from typing import (
Dict, Iterator, List, Match, Optional, Pattern, Union,
Text, IO, Tuple
)
if sys.version_info >= (3, 6):
_PathLike = os.PathLike
else:
Expand Down Expand Up @@ -59,10 +61,14 @@

_escape_sequence = re.compile(r"\\[\\'\"abfnrtv]") # type: Pattern[Text]


Binding = NamedTuple("Binding", [("key", Optional[Text]),
("value", Optional[Text]),
("original", Text)])
try:
from typing import NamedTuple, Optional, Text
Binding = NamedTuple("Binding", [("key", Optional[Text]),
("value", Optional[Text]),
("original", Text)])
except ImportError:
from collections import namedtuple
Binding = namedtuple("Binding", ["key", "value", "original"])


def decode_escapes(string):
Expand Down

0 comments on commit 6baea81

Please sign in to comment.