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
16 changes: 8 additions & 8 deletions pdm_build.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import os
from typing import Any, Dict, List
from typing import Any

from pdm.backend.hooks import Context

Expand All @@ -11,34 +11,34 @@ def pdm_build_initialize(context: Context):
# Get main version
version = metadata["version"]
# Get package names to keep in sync with the same main version
sync_dependencies: List[str] = context.config.data["tool"]["tiangolo"][
sync_dependencies: list[str] = context.config.data["tool"]["tiangolo"][
"_internal-slim-build"
]["sync-dependencies"]
# Get custom config for the current package, from the env var
config: Dict[str, Any] = context.config.data["tool"]["tiangolo"][
config: dict[str, Any] = context.config.data["tool"]["tiangolo"][
"_internal-slim-build"
]["packages"][TIANGOLO_BUILD_PACKAGE]
project_config: Dict[str, Any] = config["project"]
project_config: dict[str, Any] = config["project"]
# Get main optional dependencies, extras
optional_dependencies: Dict[str, List[str]] = metadata.get(
optional_dependencies: dict[str, list[str]] = metadata.get(
"optional-dependencies", {}
)
# Get custom optional dependencies name to always include in this (non-slim) package
include_optional_dependencies: List[str] = config.get(
include_optional_dependencies: list[str] = config.get(
"include-optional-dependencies", []
)
# Override main [project] configs with custom configs for this package
for key, value in project_config.items():
metadata[key] = value
# Get custom build config for the current package
build_config: Dict[str, Any] = (
build_config: dict[str, Any] = (
config.get("tool", {}).get("pdm", {}).get("build", {})
)
# Override PDM build config with custom build config for this package
for key, value in build_config.items():
context.config.build_config[key] = value
# Get main dependencies
dependencies: List[str] = metadata.get("dependencies", [])
dependencies: list[str] = metadata.get("dependencies", [])
# Add optional dependencies to the default dependencies for this (non-slim) package
for include_optional in include_optional_dependencies:
optional_dependencies_group = optional_dependencies.get(include_optional, [])
Expand Down
3 changes: 1 addition & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ description = "Typer, build great CLIs. Easy to code. Based on Python type hints
authors = [
{name = "Sebastián Ramírez", email = "tiangolo@gmail.com"},
]
requires-python = ">=3.8"
requires-python = ">=3.9"
classifiers = [
"Intended Audience :: Information Technology",
"Intended Audience :: System Administrators",
Expand All @@ -26,7 +26,6 @@ classifiers = [
"Development Status :: 4 - Beta",
"Intended Audience :: Developers",
"Programming Language :: Python :: 3 :: Only",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
Expand Down
8 changes: 4 additions & 4 deletions scripts/mkdocs_hooks.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Any, List, Union
from typing import Any, Union

from mkdocs.config.defaults import MkDocsConfig
from mkdocs.structure.files import Files
Expand All @@ -7,9 +7,9 @@


def generate_renamed_section_items(
items: List[Union[Page, Section, Link]], *, config: MkDocsConfig
) -> List[Union[Page, Section, Link]]:
new_items: List[Union[Page, Section, Link]] = []
items: list[Union[Page, Section, Link]], *, config: MkDocsConfig
) -> list[Union[Page, Section, Link]]:
new_items: list[Union[Page, Section, Link]] = []
for item in items:
if isinstance(item, Section):
new_title = item.title
Expand Down
3 changes: 2 additions & 1 deletion tests/assets/cli/rich_formatted_app.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from typing import Annotated

import typer
from typing_extensions import Annotated

app = typer.Typer(rich_markup_mode="rich")

Expand Down
3 changes: 2 additions & 1 deletion tests/test_ambiguous_params.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from typing import Annotated

import pytest
import typer
from typer.testing import CliRunner
Expand All @@ -8,7 +10,6 @@
MultipleTyperAnnotationsError,
_split_annotation_from_typer_annotations,
)
from typing_extensions import Annotated

runner = CliRunner()

Expand Down
2 changes: 1 addition & 1 deletion tests/test_annotated.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import sys
from pathlib import Path
from typing import Annotated

import typer
from typer.testing import CliRunner
from typing_extensions import Annotated

from .utils import needs_py310

Expand Down
3 changes: 2 additions & 1 deletion tests/test_future_annotations.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
from __future__ import annotations

from typing import Annotated

import typer
from typer.testing import CliRunner
from typing_extensions import Annotated

runner = CliRunner()

Expand Down
23 changes: 14 additions & 9 deletions tests/test_launch.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,11 @@
],
)
def test_launch_url_unix(system: str, command: str):
with patch("platform.system", return_value=system), patch(
"shutil.which", return_value=True
), patch("subprocess.Popen") as mock_popen:
with (
patch("platform.system", return_value=system),
patch("shutil.which", return_value=True),
patch("subprocess.Popen") as mock_popen,
):
typer.launch(url)

mock_popen.assert_called_once_with(
Expand All @@ -27,18 +29,21 @@ def test_launch_url_unix(system: str, command: str):


def test_launch_url_windows():
with patch("platform.system", return_value="Windows"), patch(
"webbrowser.open"
) as mock_webbrowser_open:
with (
patch("platform.system", return_value="Windows"),
patch("webbrowser.open") as mock_webbrowser_open,
):
typer.launch(url)

mock_webbrowser_open.assert_called_once_with(url)


def test_launch_url_no_xdg_open():
with patch("platform.system", return_value="Linux"), patch(
"shutil.which", return_value=None
), patch("webbrowser.open") as mock_webbrowser_open:
with (
patch("platform.system", return_value="Linux"),
patch("shutil.which", return_value=None),
patch("webbrowser.open") as mock_webbrowser_open,
):
typer.launch(url)

mock_webbrowser_open.assert_called_once_with(url)
Expand Down
10 changes: 5 additions & 5 deletions tests/test_others.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import sys
import typing
from pathlib import Path
from typing import Annotated
from unittest import mock

import click
Expand All @@ -14,7 +15,6 @@
from typer.main import solve_typer_info_defaults, solve_typer_info_help
from typer.models import ParameterInfo, TyperInfo
from typer.testing import CliRunner
from typing_extensions import Annotated

from .utils import requires_completion_permission

Expand Down Expand Up @@ -148,14 +148,14 @@ def main(name: str = typer.Option(..., callback=name_callback)):
def test_callback_4_list_none():
app = typer.Typer()

def names_callback(ctx, param, values: typing.Optional[typing.List[str]]):
def names_callback(ctx, param, values: typing.Optional[list[str]]):
if values is None:
return values
return [value.upper() for value in values]

@app.command()
def main(
names: typing.Optional[typing.List[str]] = typer.Option(
names: typing.Optional[list[str]] = typer.Option(
None, "--name", callback=names_callback
),
):
Expand All @@ -172,14 +172,14 @@ def main(


def test_empty_list_default_generator():
def empty_list() -> typing.List[str]:
def empty_list() -> list[str]:
return []

app = typer.Typer()

@app.command()
def main(
names: Annotated[typing.List[str], typer.Option(default_factory=empty_list)],
names: Annotated[list[str], typer.Option(default_factory=empty_list)],
):
print(names)

Expand Down
12 changes: 5 additions & 7 deletions tests/test_rich_markup_mode.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from typing import List

import pytest
import typer
import typer.completion
Expand Down Expand Up @@ -58,7 +56,7 @@ def main(arg: str):
),
],
)
def test_markup_mode_newline_pr815(mode: str, lines: List[str]):
def test_markup_mode_newline_pr815(mode: str, lines: list[str]):
app = typer.Typer(rich_markup_mode=mode)

@app.command()
Expand Down Expand Up @@ -96,7 +94,7 @@ def main(arg: str):
pytest.param(None, ["First line", "", "Line 1 Line 2 Line 3", ""]),
],
)
def test_markup_mode_newline_issue447(mode: str, lines: List[str]):
def test_markup_mode_newline_issue447(mode: str, lines: list[str]):
app = typer.Typer(rich_markup_mode=mode)

@app.command()
Expand Down Expand Up @@ -169,7 +167,7 @@ def main(arg: str):
),
],
)
def test_markup_mode_newline_mixed(mode: str, lines: List[str]):
def test_markup_mode_newline_mixed(mode: str, lines: list[str]):
app = typer.Typer(rich_markup_mode=mode)

@app.command()
Expand Down Expand Up @@ -213,7 +211,7 @@ def main(arg: str):
pytest.param(None, ["First line", "", "- 1 - 2 - 3", ""]),
],
)
def test_markup_mode_bullets_single_newline(mode: str, lines: List[str]):
def test_markup_mode_bullets_single_newline(mode: str, lines: list[str]):
app = typer.Typer(rich_markup_mode=mode)

@app.command()
Expand Down Expand Up @@ -256,7 +254,7 @@ def main(arg: str):
(None, ["First line", "", "- 1", "", "- 2", "", "- 3", ""]),
],
)
def test_markup_mode_bullets_double_newline(mode: str, lines: List[str]):
def test_markup_mode_bullets_double_newline(mode: str, lines: list[str]):
app = typer.Typer(rich_markup_mode=mode)

@app.command()
Expand Down
16 changes: 8 additions & 8 deletions tests/test_type_conversion.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from enum import Enum
from pathlib import Path
from typing import Any, List, Optional, Tuple
from typing import Any, Optional

import click
import pytest
Expand Down Expand Up @@ -55,7 +55,7 @@ def test_optional_tuple():
app = typer.Typer()

@app.command()
def opt(number: Optional[Tuple[int, int]] = None):
def opt(number: Optional[tuple[int, int]] = None):
if number:
print(f"Number: {number}")
else:
Expand Down Expand Up @@ -90,7 +90,7 @@ class SomeEnum(Enum):

@pytest.mark.parametrize(
"type_annotation",
[List[Path], List[SomeEnum], List[str]],
[list[Path], list[SomeEnum], list[str]],
)
def test_list_parameters_convert_to_lists(type_annotation):
# Lists containing objects that are converted by Click (i.e. not Path or Enum)
Expand All @@ -111,11 +111,11 @@ def list_conversion(container: type_annotation):
@pytest.mark.parametrize(
"type_annotation",
[
Tuple[str, str],
Tuple[str, Path],
Tuple[Path, Path],
Tuple[str, SomeEnum],
Tuple[SomeEnum, SomeEnum],
tuple[str, str],
tuple[str, Path],
tuple[Path, Path],
tuple[str, SomeEnum],
tuple[SomeEnum, SomeEnum],
],
)
def test_tuple_parameter_elements_are_converted_recursively(type_annotation):
Expand Down
18 changes: 9 additions & 9 deletions typer/_completion_classes.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import os
import re
import sys
from typing import Any, Dict, List, Tuple
from typing import Any

import click
import click.parser
Expand Down Expand Up @@ -38,14 +38,14 @@ class BashComplete(click.shell_completion.BashComplete):
name = Shells.bash.value
source_template = COMPLETION_SCRIPT_BASH

def source_vars(self) -> Dict[str, Any]:
def source_vars(self) -> dict[str, Any]:
return {
"complete_func": self.func_name,
"autocomplete_var": self.complete_var,
"prog_name": self.prog_name,
}

def get_completion_args(self) -> Tuple[List[str], str]:
def get_completion_args(self) -> tuple[list[str], str]:
cwords = click_split_arg_string(os.environ["COMP_WORDS"])
cword = int(os.environ["COMP_CWORD"])
args = cwords[1:cword]
Expand Down Expand Up @@ -74,14 +74,14 @@ class ZshComplete(click.shell_completion.ZshComplete):
name = Shells.zsh.value
source_template = COMPLETION_SCRIPT_ZSH

def source_vars(self) -> Dict[str, Any]:
def source_vars(self) -> dict[str, Any]:
return {
"complete_func": self.func_name,
"autocomplete_var": self.complete_var,
"prog_name": self.prog_name,
}

def get_completion_args(self) -> Tuple[List[str], str]:
def get_completion_args(self) -> tuple[list[str], str]:
completion_args = os.getenv("_TYPER_COMPLETE_ARGS", "")
cwords = click_split_arg_string(completion_args)
args = cwords[1:]
Expand Down Expand Up @@ -125,14 +125,14 @@ class FishComplete(click.shell_completion.FishComplete):
name = Shells.fish.value
source_template = COMPLETION_SCRIPT_FISH

def source_vars(self) -> Dict[str, Any]:
def source_vars(self) -> dict[str, Any]:
return {
"complete_func": self.func_name,
"autocomplete_var": self.complete_var,
"prog_name": self.prog_name,
}

def get_completion_args(self) -> Tuple[List[str], str]:
def get_completion_args(self) -> tuple[list[str], str]:
completion_args = os.getenv("_TYPER_COMPLETE_ARGS", "")
cwords = click_split_arg_string(completion_args)
args = cwords[1:]
Expand Down Expand Up @@ -178,14 +178,14 @@ class PowerShellComplete(click.shell_completion.ShellComplete):
name = Shells.powershell.value
source_template = COMPLETION_SCRIPT_POWER_SHELL

def source_vars(self) -> Dict[str, Any]:
def source_vars(self) -> dict[str, Any]:
return {
"complete_func": self.func_name,
"autocomplete_var": self.complete_var,
"prog_name": self.prog_name,
}

def get_completion_args(self) -> Tuple[List[str], str]:
def get_completion_args(self) -> tuple[list[str], str]:
completion_args = os.getenv("_TYPER_COMPLETE_ARGS", "")
incomplete = os.getenv("_TYPER_COMPLETE_WORD_TO_COMPLETE", "")
cwords = click_split_arg_string(completion_args)
Expand Down
Loading