Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Use 'type: ignore' instead of complex workarounds.
  • Loading branch information
qnighy committed Mar 16, 2019
commit bc873a3fb65cd7bb4fe102f241f1d166527e2c9e
18 changes: 6 additions & 12 deletions src/dotenv/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,7 @@ def _get_stream(self):
yield stream
else:
if self.verbose:
if not TYPE_CHECKING or sys.version_info >= (3, 0):
warnings.warn("File doesn't exist {}".format(self.dotenv_path))
warnings.warn("File doesn't exist {}".format(self.dotenv_path)) # type: ignore
yield StringIO('')

def dict(self):
Expand Down Expand Up @@ -171,8 +170,7 @@ def set_as_environment_variables(self, override=False):
if isinstance(k, text_type) or isinstance(v, text_type):
k = k.encode('ascii')
v = v.encode('ascii')
if not TYPE_CHECKING or sys.version_info >= (3, 0):
os.environ[k] = v
os.environ[k] = v # type: ignore

return True

Expand All @@ -186,8 +184,7 @@ def get(self, key):
return data[key]

if self.verbose:
if not TYPE_CHECKING or sys.version_info >= (3, 0):
warnings.warn("key %s not found in %s." % (key, self.dotenv_path))
warnings.warn("key %s not found in %s." % (key, self.dotenv_path)) # type: ignore

return None # NOTE: PEP8 compliance required by mypy
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's OK to not have a comment here. PEP 8 compliance is implicit in the whole code base and removing this return None shouldn't trigger a lint error (if linting is done in CI).


Expand Down Expand Up @@ -227,8 +224,7 @@ def set_key(dotenv_path, key_to_set, value_to_set, quote_mode="always"):
"""
value_to_set = value_to_set.strip("'").strip('"')
if not os.path.exists(dotenv_path):
if not TYPE_CHECKING or sys.version_info >= (3, 0):
warnings.warn("can't write to %s - it doesn't exist." % dotenv_path)
warnings.warn("can't write to %s - it doesn't exist." % dotenv_path) # type: ignore
return None, key_to_set, value_to_set

if " " in value_to_set:
Expand Down Expand Up @@ -260,8 +256,7 @@ def unset_key(dotenv_path, key_to_unset, quote_mode="always"):
If the given key doesn't exist in the .env, fails
"""
if not os.path.exists(dotenv_path):
if not TYPE_CHECKING or sys.version_info >= (3, 0):
warnings.warn("can't delete from %s - it doesn't exist." % dotenv_path)
warnings.warn("can't delete from %s - it doesn't exist." % dotenv_path) # type: ignore
return None, key_to_unset

removed = False
Expand All @@ -273,8 +268,7 @@ def unset_key(dotenv_path, key_to_unset, quote_mode="always"):
dest.write(mapping.original)

if not removed:
if not TYPE_CHECKING or sys.version_info >= (3, 0):
warnings.warn("key %s not removed from %s - key doesn't exist." % (key_to_unset, dotenv_path))
warnings.warn("key %s not removed from %s - key doesn't exist." % (key_to_unset, dotenv_path)) # type: ignore
return None, key_to_unset

return removed, key_to_unset
Expand Down