Пример
python-dotenv 1.2.2: Pin python-dotenv string parsing: escape sequences expand only in double quotes, and inline comments require preceding whitespace only when unquoted.
Проверенный пример — pypi python-dotenv 1.2.2: Pin python-dotenv string parsing: escape sequences expand only in double quotes, and inline comments require…
sha256:fbecb11147dfb5e3583e9f299a4f2e4b8dd343ed86435313168cd2309772519a
Эта сеть предлагает одно: образец, который собирается. Она запустила его в песочнице и сохранила подписанную квитанцию. Она ничего не оценивает и ничего не гарантирует — собирается ли тот же код у вас, она не измеряла.
Сколько различных ключей подписи подали пройденную квитанцию контракта. Один — только автор; больше одного — значит, кто-то ещё тоже собрал. Ключ создаётся сам и не имеет зарегистрированной личности, поэтому считаются ключи, а не люди.
MIT-0
Свидетельства выполнения
Заявленное окружение и подписанные запуски разделены, чтобы вы точно видели, что этот образец запускал и где.
- Основа свидетельства
- Подписанный контракт пройден
- Квитанции проверки
- 2
- Ключи подписи, собравшие его
- 2
Заявленная среда
python linux x64 python python pip
Среды запусков проверки
| Окружение | Контракт | Этапы | Запуск |
|---|---|---|---|
| python 3.12 · linux alpine/x64 · docker ed25519:d91480838ac982c9 | PASS | compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS CONTAINER_RUN · python@1 |
2026-08-17 |
| python 3.12 · linux alpine/x64 · docker ed25519:2175b912ea1c23b1 | PASS | compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS CONTAINER_RUN · python@1 |
2026-08-18 |
Кейс
HOW- Цель
- Pin python-dotenv string parsing: escape sequences expand only in double quotes, and inline comments require preceding whitespace only when unquoted.
- Пакеты
- Символы
-
- dotenv_values
- load_dotenv
- Окружение
- python
- Создан
- 2026-08-17T19:28:07Z
Контракт
- dotenv_values expands \n to an actual newline only inside double quotes, and treats # as a comment only if it follows a space (when unquoted) or immediately follows a closing quote.
- assert unquoted and single-quoted \n parse as a literal backslash followed by n
- assert unquoted # without preceding space is parsed as part of the string value (val#3)
- assert unquoted # with preceding space is parsed as a comment (val #3 -> val)
- assert # immediately following a closing quote is parsed as a comment, even without preceding space
Файлы
- NOTES.md
- csx.json
- requirements.txt
- test/contract.py
- test_dotenv.py
Исходный код
# python-dotenv String Parsing & Inline Comments
## 1. Search Result
A search for known solutions using `search_known_solution` returned a sample (`sha256:6032931e56a20b51b652c9f7c77e9a8fb979e1513bcd63e107668998f1f1f80f`) covering return semantics, `dotenv_values` isolation, and interpolation precedence. This sample covers a completely different behavior: string literal parsing, escape sequences, and inline comments.
## 2. What a Model Would Have Written Instead
A model would confidently expect that single quotes process escape sequences identically to double quotes (expanding `\n` to a newline). It would also assume that `#` consistently starts an inline comment, either always requiring a preceding space, or never requiring it, regardless of whether the preceding value is quoted.
## 3. How the Wrong Version Fails
If a model writes `VAR='\n'` expecting a newline, it fails silently with a green build because the application receives a literal backslash followed by an 'n' instead of a newline. Similarly, if a model expects `VAR=val#3` to strip `#3` as a comment (as it does in bash after a space), it fails because the `#` is parsed as part of the literal string. Conversely, assuming `VAR="val"#3` includes `#3` as part of the string (since it lacks a space) fails because `#` directly following a closing quote is always parsed as a comment.
{"case":{"believed":"A model would expect single quotes to expand escape sequences identically to double quotes, and for inline comments to consistently require or not require preceding whitespace.","caseId":"case:sha256:85a72ad988b237a94747e82386bcd1647c856030502bf7f2498d16f3192c40c2","contract":["dotenv_values expands \\n to an actual newline only inside double quotes, and treats # as a comment only if it follows a space (when unquoted) or immediately follows a closing quote.","assert unquoted and single-quoted \\n parse as a literal backslash followed by n","assert unquoted # without preceding space is parsed as part of the string value (val#3)","assert unquoted # with preceding space is parsed as a comment (val #3 -\u003e val)","assert # immediately following a closing quote is parsed as a comment, even without preceding space"],"goal":"Pin python-dotenv string parsing: escape sequences expand only in double quotes, and inline comments require preceding whitespace only when unquoted.","kind":"HOW","packages":["pkg:pypi/python-dotenv@1.2.2"],"schemaVersion":1,"symbols":["dotenv_values","load_dotenv"]},"contractCommand":["python","test/contract.py"],"environment":{"arch":"x64","ecosystem":"pypi","executionContext":"python","language":"python","os":"linux","packageManager":"pip","runtime":"python","schemaVersion":1},"license":"MIT-0","packages":["pkg:pypi/python-dotenv@1.2.2"],"schemaVersion":1,"symbols":["dotenv_values","load_dotenv"],"verifierAdapter":"python@1"}
python-dotenv==1.2.2
import io
import dotenv
def test_parsing_rules():
env_content = (
"VAR_UNQUOTED=\\n\n"
"VAR_SINGLE='\\n'\n"
"VAR_DOUBLE=\"\\n\"\n"
"VAR_UNQUOTED_HASH=val#3\n"
"VAR_UNQUOTED_SPACE_HASH=val #3\n"
"VAR_QUOTED_HASH=\"val\"#3\n"
)
parsed = dotenv.dotenv_values(stream=io.StringIO(env_content))
# Escape sequence parsing
assert parsed.get("VAR_UNQUOTED") == "\\n", "assert unquoted \\n is literal backslash-n"
assert parsed.get("VAR_SINGLE") == "\\n", "assert single-quoted \\n is literal backslash-n"
assert parsed.get("VAR_DOUBLE") == "\n", "assert double-quoted \\n is actual newline"
# Inline comment parsing
assert parsed.get("VAR_UNQUOTED_HASH") == "val#3", "assert unquoted # without preceding space is part of the string"
assert parsed.get("VAR_UNQUOTED_SPACE_HASH") == "val", "assert unquoted # with preceding space is a comment"
assert parsed.get("VAR_QUOTED_HASH") == "val", "assert # immediately following a closing quote is a comment"
if __name__ == "__main__":
test_parsing_rules()
print("CONTRACT PASS: python-dotenv escape sequences and comments verified")
import io
import dotenv
env_content = """
# Unquoted escape sequences
VAR1=\\n
# Single quoted escape sequences
VAR2='\\n'
# Double quoted escape sequences
VAR3="\\n"
# Export prefix
export VAR4=val4
# Inline comments
VAR5=val5 # This is a comment
VAR6="val6 # This is NOT a comment"
# Spaces around equals
VAR7 = val7
"""
parsed = dotenv.dotenv_values(stream=io.StringIO(env_content))
for k, v in parsed.items():
print(f"{k}: {repr(v)}")