New feature#2
Conversation
| with open(dotenv_path or '.env') as f: | ||
|
|
||
| content = f.read() |
There was a problem hiding this comment.
Review #1
Issue:
FileNotFoundError: stream argument ignored
Where:
load_dotenv in src/dotenv/main.py
Description:
stream-based loading breaks when dotenv_path is None and no .env exists
New code removed prior stream-based behavior and now unconditionally executes open(dotenv_path or '.env') at src/dotenv/main.py:346-348. The function signature still accepts stream at src/dotenv/main.py:323, but the new implementation never uses it. Evidence-1 shows the previous implementation passed stream=stream into DotEnv and only fell back when both dotenv_path and stream were None, so this is a new API/behavior regression that can raise FileNotFoundError for stream-only callers.
+ with open(dotenv_path or '.env') as f:
+
+ content = f.read()Feedback: 👎
| if line.strip() and not line.startswith('#'): | ||
|
|
||
| key, value = line.split('=', 1) |
There was a problem hiding this comment.
Review #2
Issue:
ValueError: malformed .env line crashes parser
Where:
parse_dotenv in src/dotenv/main.py
Description:
loading crashes when a non-comment line lacks an equals sign
New parser code only skips blank/comment lines at src/dotenv/main.py:361, then unconditionally executes line.split('=', 1) at line 363. A non-comment malformed line without = raises ValueError, and the only traced caller load_dotenv passes raw file content directly from open(...).read() to parse_dotenv with no validation or exception handling at src/dotenv/main.py:346-350.
+ key, value = line.split('=', 1)Feedback: 👎
| try: | ||
|
|
||
| schema['type'](value) | ||
| except ValueError: | ||
|
|
||
| raise ValueError(f"Invalid type for {var_name}: {value}") |
There was a problem hiding this comment.
Review theskumar#3
Issue:
TypeError escapes for invalid schema type callables
Where:
EnvValidator.validate in src/dotenv/validator.py
Description:
validation crashes when schema type is a callable like bool(None) replacement raising TypeError
New file in this PR. EnvValidator.validate wraps schema['type'](value) in try/except but catches only ValueError at src/dotenv/validator.py:25-30. The schema callable is caller-controlled via add_schema(..., var_type, ...) at src/dotenv/validator.py:8-13, so a callable that raises TypeError will escape unhandled. No broader enclosing handler is present in the function.
+ try:
+
+ schema['type'](value)
+ except ValueError:Feedback: 👎
No description provided.