Skip to content

Commit b04c314

Browse files
committed
Adds TYPER_STANDARD_TRACEBACK variable
Keeps support fo `_TYPER_STANDARD_TRACEBACK` but notes as deprecated because: - It is non-standard for an advertised env to start with an underscore. - Environment variables that start with an underscore have been observed as causing issues in some execution environments (e.g. with AWS Lambda). See: #1284
1 parent 99449e7 commit b04c314

File tree

7 files changed

+42
-12
lines changed

7 files changed

+42
-12
lines changed

docs/tutorial/exceptions.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -235,14 +235,14 @@ TypeError: can only concatenate str (not "int") to str
235235

236236
</div>
237237

238-
You could also achieve the same with the environment variable `_TYPER_STANDARD_TRACEBACK=1`.
238+
You could also achieve the same with the environment variable `TYPER_STANDARD_TRACEBACK=1` (or by setting the deprecated variable `_TYPER_STANDARD_TRACEBACK=1`).
239239

240240
This will work for any other Typer program too, in case you need to debug a problem in a Typer program made by someone else:
241241

242242
<div class="termy">
243243

244244
```console
245-
export _TYPER_STANDARD_TRACEBACK=1
245+
export TYPER_STANDARD_TRACEBACK=1
246246
$ python main.py
247247

248248

tests/test_tracebacks.py

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,11 @@ def test_traceback_no_rich():
1010
[sys.executable, "-m", "coverage", "run", str(file_path)],
1111
capture_output=True,
1212
encoding="utf-8",
13-
env={**os.environ, "_TYPER_STANDARD_TRACEBACK": ""},
13+
env={
14+
**os.environ,
15+
"TYPER_STANDARD_TRACEBACK": "",
16+
"_TYPER_STANDARD_TRACEBACK": "",
17+
},
1418
)
1519
assert "return get_command(self)(*args, **kwargs)" not in result.stderr
1620

@@ -25,7 +29,11 @@ def test_traceback_no_rich_short_disable():
2529
[sys.executable, "-m", "coverage", "run", str(file_path)],
2630
capture_output=True,
2731
encoding="utf-8",
28-
env={**os.environ, "_TYPER_STANDARD_TRACEBACK": ""},
32+
env={
33+
**os.environ,
34+
"TYPER_STANDARD_TRACEBACK": "",
35+
"_TYPER_STANDARD_TRACEBACK": "",
36+
},
2937
)
3038
assert "return get_command(self)(*args, **kwargs)" not in result.stderr
3139

@@ -40,7 +48,11 @@ def test_unmodified_traceback():
4048
[sys.executable, "-m", "coverage", "run", str(file_path)],
4149
capture_output=True,
4250
encoding="utf-8",
43-
env={**os.environ, "_TYPER_STANDARD_TRACEBACK": ""},
51+
env={
52+
**os.environ,
53+
"TYPER_STANDARD_TRACEBACK": "",
54+
"_TYPER_STANDARD_TRACEBACK": "",
55+
},
4456
)
4557
assert "morty" in result.stdout, "the call to the first app should work normally"
4658
assert "return callback(**use_params)" in result.stderr, (

tests/test_tutorial/test_exceptions/test_tutorial001.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,11 @@ def test_traceback_rich():
1616
[sys.executable, "-m", "coverage", "run", str(file_path)],
1717
capture_output=True,
1818
encoding="utf-8",
19-
env={**os.environ, "_TYPER_STANDARD_TRACEBACK": ""},
19+
env={
20+
**os.environ,
21+
"TYPER_STANDARD_TRACEBACK": "",
22+
"_TYPER_STANDARD_TRACEBACK": "",
23+
},
2024
)
2125
assert "return get_command(self)(*args, **kwargs)" not in result.stderr
2226

@@ -32,7 +36,7 @@ def test_standard_traceback_env_var():
3236
[sys.executable, "-m", "coverage", "run", str(file_path)],
3337
capture_output=True,
3438
encoding="utf-8",
35-
env={**os.environ, "_TYPER_STANDARD_TRACEBACK": "1"},
39+
env={**os.environ, "TYPER_STANDARD_TRACEBACK": "1"},
3640
)
3741
assert "return get_command(self)(*args, **kwargs)" in result.stderr
3842

tests/test_tutorial/test_exceptions/test_tutorial002.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,11 @@ def test_traceback_rich():
1616
[sys.executable, "-m", "coverage", "run", str(file_path), "secret"],
1717
capture_output=True,
1818
encoding="utf-8",
19-
env={**os.environ, "_TYPER_STANDARD_TRACEBACK": ""},
19+
env={
20+
**os.environ,
21+
"TYPER_STANDARD_TRACEBACK": "",
22+
"_TYPER_STANDARD_TRACEBACK": "",
23+
},
2024
)
2125
assert "return get_command(self)(*args, **kwargs)" not in result.stderr
2226

@@ -32,7 +36,7 @@ def test_standard_traceback_env_var():
3236
[sys.executable, "-m", "coverage", "run", str(file_path), "secret"],
3337
capture_output=True,
3438
encoding="utf-8",
35-
env={**os.environ, "_TYPER_STANDARD_TRACEBACK": "1"},
39+
env={**os.environ, "TYPER_STANDARD_TRACEBACK": "1"},
3640
)
3741
assert "return get_command(self)(*args, **kwargs)" in result.stderr
3842

tests/test_tutorial/test_exceptions/test_tutorial003.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,11 @@ def test_traceback_rich_pretty_short_disable():
1616
[sys.executable, "-m", "coverage", "run", str(file_path)],
1717
capture_output=True,
1818
encoding="utf-8",
19-
env={**os.environ, "_TYPER_STANDARD_TRACEBACK": ""},
19+
env={
20+
**os.environ,
21+
"TYPER_STANDARD_TRACEBACK": "",
22+
"_TYPER_STANDARD_TRACEBACK": "",
23+
},
2024
)
2125
assert "return get_command(self)(*args, **kwargs)" not in result.stderr
2226

tests/test_tutorial/test_exceptions/test_tutorial004.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,11 @@ def test_rich_pretty_exceptions_disable():
1616
[sys.executable, "-m", "coverage", "run", str(file_path)],
1717
capture_output=True,
1818
encoding="utf-8",
19-
env={**os.environ, "_TYPER_STANDARD_TRACEBACK": ""},
19+
env={
20+
**os.environ,
21+
"TYPER_STANDARD_TRACEBACK": "",
22+
"_TYPER_STANDARD_TRACEBACK": "",
23+
},
2024
)
2125
assert "return get_command(self)(*args, **kwargs)" in result.stderr
2226

typer/main.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,9 @@ def except_hook(
6565
exception_config: Union[DeveloperExceptionConfig, None] = getattr(
6666
exc_value, _typer_developer_exception_attr_name, None
6767
)
68-
standard_traceback = os.getenv("_TYPER_STANDARD_TRACEBACK")
68+
standard_traceback = os.getenv(
69+
"TYPER_STANDARD_TRACEBACK", os.getenv("_TYPER_STANDARD_TRACEBACK")
70+
)
6971
if (
7072
standard_traceback
7173
or not exception_config

0 commit comments

Comments
 (0)