Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/tutorial/arguments/default.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ Hello Camila

And we can even make the default value be dynamically generated by passing a function as the `default_factory` argument:

{* docs_src/arguments/default/tutorial002_an.py hl[10:11,14] *}
{* docs_src/arguments/default/tutorial002_an.py hl[9:10,14] *}

In this case, we created the function `get_name` that will just return a random `str` each time.

Expand Down
2 changes: 1 addition & 1 deletion docs_src/arguments/default/tutorial002.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
app = typer.Typer()


@app.command()
def get_name():
return random.choice(["Deadpool", "Rick", "Morty", "Hiro"])


@app.command()
Copy link
Member Author

Choose a reason for hiding this comment

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

This one (and in the next file) was a bug from #1418

def main(name: str = typer.Argument(default_factory=get_name)):
print(f"Hello {name}")

Expand Down
2 changes: 1 addition & 1 deletion docs_src/arguments/default/tutorial002_an.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
app = typer.Typer()


@app.command()
def get_name():
return random.choice(["Deadpool", "Rick", "Morty", "Hiro"])


@app.command()
def main(name: Annotated[str, typer.Argument(default_factory=get_name)]):
print(f"Hello {name}")

Expand Down
4 changes: 1 addition & 3 deletions tests/test_completion/test_completion_install.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,14 @@
from unittest import mock

import shellingham
import typer
from typer.testing import CliRunner

from docs_src.typer_app import tutorial001 as mod

from ..utils import requires_completion_permission

runner = CliRunner()
app = typer.Typer()
app.command()(mod.main)
app = mod.app


@requires_completion_permission
Expand Down
4 changes: 1 addition & 3 deletions tests/test_completion/test_completion_show.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,12 @@
from unittest import mock

import shellingham
import typer
from typer.testing import CliRunner

from docs_src.typer_app import tutorial001 as mod

runner = CliRunner()
app = typer.Typer()
app.command()(mod.main)
app = mod.app


def test_completion_show_no_shell():
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
import subprocess
import sys

import typer
from typer.testing import CliRunner

from docs_src.arguments.default import tutorial001 as mod

runner = CliRunner()

app = typer.Typer()
app.command()(mod.main)
app = mod.app


def test_help():
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
import subprocess
import sys

import typer
from typer.testing import CliRunner

from docs_src.arguments.default import tutorial001_an as mod

runner = CliRunner()

app = typer.Typer()
app.command()(mod.main)
app = mod.app


def test_help():
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
import subprocess
import sys

import typer
from typer.testing import CliRunner

from docs_src.arguments.default import tutorial002 as mod

runner = CliRunner()

app = typer.Typer()
app.command()(mod.main)
app = mod.app


def test_help():
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
import subprocess
import sys

import typer
from typer.testing import CliRunner

from docs_src.arguments.default import tutorial002_an as mod

runner = CliRunner()

app = typer.Typer()
app.command()(mod.main)
app = mod.app


def test_help():
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@
from docs_src.arguments.envvar import tutorial001 as mod

runner = CliRunner()

app = typer.Typer()
app.command()(mod.main)
app = mod.app


def test_help():
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@

runner = CliRunner()

app = typer.Typer()
app.command()(mod.main)
app = mod.app


def test_help():
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
import subprocess
import sys

import typer
from typer.testing import CliRunner

from docs_src.arguments.envvar import tutorial002 as mod

runner = CliRunner()

app = typer.Typer()
app.command()(mod.main)
app = mod.app


def test_help():
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
import subprocess
import sys

import typer
from typer.testing import CliRunner

from docs_src.arguments.envvar import tutorial002_an as mod

runner = CliRunner()

app = typer.Typer()
app.command()(mod.main)
app = mod.app


def test_help():
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
import subprocess
import sys

import typer
from typer.testing import CliRunner

from docs_src.arguments.envvar import tutorial003 as mod

runner = CliRunner()

app = typer.Typer()
app.command()(mod.main)
app = mod.app


def test_help():
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
import subprocess
import sys

import typer
from typer.testing import CliRunner

from docs_src.arguments.envvar import tutorial003_an as mod

runner = CliRunner()

app = typer.Typer()
app.command()(mod.main)
app = mod.app


def test_help():
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@
from docs_src.arguments.help import tutorial001 as mod

runner = CliRunner()

app = typer.Typer()
app.command()(mod.main)
app = mod.app


def test_help():
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@
from docs_src.arguments.help import tutorial001_an as mod

runner = CliRunner()

app = typer.Typer()
app.command()(mod.main)
app = mod.app


def test_help():
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
import subprocess
import sys

import typer
from typer.testing import CliRunner

from docs_src.arguments.help import tutorial002 as mod

runner = CliRunner()

app = typer.Typer()
app.command()(mod.main)
app = mod.app


def test_help():
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
import subprocess
import sys

import typer
from typer.testing import CliRunner

from docs_src.arguments.help import tutorial002_an as mod

runner = CliRunner()

app = typer.Typer()
app.command()(mod.main)
app = mod.app


def test_help():
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
import subprocess
import sys

import typer
from typer.testing import CliRunner

from docs_src.arguments.help import tutorial003 as mod

runner = CliRunner()

app = typer.Typer()
app.command()(mod.main)
app = mod.app


def test_help():
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
import subprocess
import sys

import typer
from typer.testing import CliRunner

from docs_src.arguments.help import tutorial003_an as mod

runner = CliRunner()

app = typer.Typer()
app.command()(mod.main)
app = mod.app


def test_help():
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
import subprocess
import sys

import typer
from typer.testing import CliRunner

from docs_src.arguments.help import tutorial004 as mod

runner = CliRunner()

app = typer.Typer()
app.command()(mod.main)
app = mod.app


def test_help():
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
import subprocess
import sys

import typer
from typer.testing import CliRunner

from docs_src.arguments.help import tutorial004_an as mod

runner = CliRunner()

app = typer.Typer()
app.command()(mod.main)
app = mod.app


def test_help():
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
import subprocess
import sys

import typer
from typer.testing import CliRunner

from docs_src.arguments.help import tutorial005 as mod

runner = CliRunner()

app = typer.Typer()
app.command()(mod.main)
app = mod.app


def test_help():
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
import subprocess
import sys

import typer
from typer.testing import CliRunner

from docs_src.arguments.help import tutorial005_an as mod

runner = CliRunner()

app = typer.Typer()
app.command()(mod.main)
app = mod.app


def test_help():
Expand Down
Loading
Loading