Skip to content
Myr

Merge pull request #2939 from sharmaadarsh563/2937-correct-load_dotenv-return-value

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Fix #2937: Ensure the consistency in load_dotenv's return type

authored by David Lord · committed by GitHub · parents d9fa28b, db8cb31 · Browse files · 3 files+19 added−3 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

3 files+19 added−3 removed

  • tests:+4 added−1 removed
  • other:+15 added−2 removed

3 files+19 added−3 removed

modified:flask/cli.py+12 added-2 removed
596 unmodified lines
597598 :param path: Load the file at this location instead of searching.599 :return: ``True`` if a file was loaded.600601 .. versionchanged:: 1.1.0602 Returns ``False`` when python-dotenv is not installed, or when603 the given path isn't a file.604605 .. versionadded:: 1.0606 """607 if dotenv is None:608 if path or os.path.isfile(".env") or os.path.isfile(".flaskenv"):
1 unmodified line
610 " * Tip: There are .env or .flaskenv files present."611 ' Do "pip install python-dotenv" to use them.',612 fg="yellow",613 )610 return614615 return False616617 # if the given path specifies the actual file then return True,618 # else False619 if path is not None:620 if os.path.isfile(path):613 return dotenv.load_dotenv(path)621 return dotenv.load_dotenv(path)622623 return False624625 new_dir = None626627 for name in (".env", ".flaskenv"):628 path = dotenv.find_dotenv(name, usecwd=True)
296 unmodified lines
modified:tests/test_cli.py+4 added-1 removed
511 unmodified lines
512 monkeypatch._setitem.append((os.environ, item, notset))513514 monkeypatch.setenv("EGGS", "3")515 monkeypatch.chdir(os.path.join(test_path, "cliapp", "inner1"))516 load_dotenv()516 assert load_dotenv()517 assert os.getcwd() == test_path518 # .flaskenv doesn't overwrite .env519 assert os.environ["FOO"] == "env"520 # set only in .flaskenv
2 unmodified lines
523 assert os.environ["SPAM"] == "1"524 # set manually, files don't overwrite525 assert os.environ["EGGS"] == "3"526527 # Non existent file should not load528 assert not load_dotenv('non-existent-file')529530531@need_dotenv532def test_dotenv_path(monkeypatch):533 for item in ("FOO", "BAR", "EGGS"):534 monkeypatch._setitem.append((os.environ, item, notset))
77 unmodified lines
modified:CHANGES.rst+3 added
42 unmodified lines
43- Allow customizing the :attr:`Flask.url_map_class` used for routing.44 :pr:`3069`45- The development server port can be set to 0, which tells the OS to46 pick an available port. :issue:`2926`47- The return value from :meth:`cli.load_dotenv` is more consistent48 with the documentation. It will return ``False`` if python-dotenv is49 not installed, or if the given path isn't a file. :issue:`2937`5051.. _#2935: https://github.com/pallets/flask/issues/293552.. _#2957: https://github.com/pallets/flask/issues/295753.. _#2994: https://github.com/pallets/flask/pull/2994
948 unmodified lines