Skip to content

Commit

Permalink
chore: enable pep 563/585
Browse files Browse the repository at this point in the history
  • Loading branch information
branchvincent authored and neersighted committed Feb 28, 2022
1 parent 1d4f4a0 commit da9680b
Show file tree
Hide file tree
Showing 242 changed files with 2,297 additions and 2,107 deletions.
2 changes: 1 addition & 1 deletion .flake8
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ inline-quotes = double
# Allow omission of a return type hint for __init__ if at least one argument is annotated
# used by flake8-annotations
mypy-init-return = true
enable-extensions = TC, TC2
enable-extensions = TC, TC1
type-checking-exempt-modules = typing, typing-extensions
eradicate-whitelist-extend = ^-.*;
extend-ignore =
Expand Down
4 changes: 3 additions & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,16 @@ repos:
hooks:
- id: pyupgrade
args: [--py37-plus]
exclude: '^(install|get)-poetry.py$'
exclude: ^(install|get)-poetry.py$

- repo: https://github.com/pycqa/isort
rev: 5.10.1
hooks:
- id: isort
name: "isort (python)"
types: [python]
args: [--add-import, from __future__ import annotations]
exclude: ^(install|get)-poetry.py$
- id: isort
name: "isort (pyi)"
types: [pyi]
Expand Down
3 changes: 3 additions & 0 deletions src/poetry/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
from __future__ import annotations


__path__ = __import__("pkgutil").extend_path(__path__, __name__)
2 changes: 2 additions & 0 deletions src/poetry/__main__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

import sys


Expand Down
3 changes: 3 additions & 0 deletions src/poetry/__version__.py
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
from __future__ import annotations


__version__ = "1.2.0a2"
30 changes: 15 additions & 15 deletions src/poetry/config/config.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

import os
import re

Expand All @@ -6,8 +8,6 @@
from typing import TYPE_CHECKING
from typing import Any
from typing import Callable
from typing import Dict
from typing import Optional

from poetry.config.dict_config_source import DictConfigSource
from poetry.locations import CACHE_DIR
Expand All @@ -31,7 +31,7 @@ def int_normalizer(val: str) -> int:

class Config:

default_config: Dict[str, Any] = {
default_config: dict[str, Any] = {
"cache-dir": str(CACHE_DIR),
"virtualenvs": {
"create": True,
Expand All @@ -45,43 +45,43 @@ class Config:
}

def __init__(
self, use_environment: bool = True, base_dir: Optional[Path] = None
self, use_environment: bool = True, base_dir: Path | None = None
) -> None:
self._config = deepcopy(self.default_config)
self._use_environment = use_environment
self._base_dir = base_dir
self._config_source: "ConfigSource" = DictConfigSource()
self._auth_config_source: "ConfigSource" = DictConfigSource()
self._config_source: ConfigSource = DictConfigSource()
self._auth_config_source: ConfigSource = DictConfigSource()

@property
def config(self) -> Dict:
def config(self) -> dict:
return self._config

@property
def config_source(self) -> "ConfigSource":
def config_source(self) -> ConfigSource:
return self._config_source

@property
def auth_config_source(self) -> "ConfigSource":
def auth_config_source(self) -> ConfigSource:
return self._auth_config_source

def set_config_source(self, config_source: "ConfigSource") -> "Config":
def set_config_source(self, config_source: ConfigSource) -> Config:
self._config_source = config_source

return self

def set_auth_config_source(self, config_source: "ConfigSource") -> "Config":
def set_auth_config_source(self, config_source: ConfigSource) -> Config:
self._auth_config_source = config_source

return self

def merge(self, config: Dict[str, Any]) -> None:
def merge(self, config: dict[str, Any]) -> None:
from poetry.utils.helpers import merge_dicts

merge_dicts(self._config, config)

def all(self) -> Dict[str, Any]:
def _all(config: Dict, parent_key: str = "") -> Dict:
def all(self) -> dict[str, Any]:
def _all(config: dict, parent_key: str = "") -> dict:
all_ = {}

for key in config:
Expand All @@ -100,7 +100,7 @@ def _all(config: Dict, parent_key: str = "") -> Dict:

return _all(self.config)

def raw(self) -> Dict[str, Any]:
def raw(self) -> dict[str, Any]:
return self._config

def get(self, setting_name: str, default: Any = None) -> Any:
Expand Down
2 changes: 2 additions & 0 deletions src/poetry/config/config_source.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

from typing import Any


Expand Down
7 changes: 4 additions & 3 deletions src/poetry/config/dict_config_source.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
from __future__ import annotations

from typing import Any
from typing import Dict

from poetry.config.config_source import ConfigSource


class DictConfigSource(ConfigSource):
def __init__(self) -> None:
self._config: Dict[str, Any] = {}
self._config: dict[str, Any] = {}

@property
def config(self) -> Dict[str, Any]:
def config(self) -> dict[str, Any]:
return self._config

def add_property(self, key: str, value: Any) -> None:
Expand Down
8 changes: 5 additions & 3 deletions src/poetry/config/file_config_source.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

from contextlib import contextmanager
from typing import TYPE_CHECKING
from typing import Any
Expand All @@ -15,7 +17,7 @@


class FileConfigSource(ConfigSource):
def __init__(self, file: "TOMLFile", auth_config: bool = False) -> None:
def __init__(self, file: TOMLFile, auth_config: bool = False) -> None:
self._file = file
self._auth_config = auth_config

Expand All @@ -24,7 +26,7 @@ def name(self) -> str:
return str(self._file.path)

@property
def file(self) -> "TOMLFile":
def file(self) -> TOMLFile:
return self._file

def add_property(self, key: str, value: Any) -> None:
Expand Down Expand Up @@ -58,7 +60,7 @@ def remove_property(self, key: str) -> None:
current_config = current_config[key]

@contextmanager
def secure(self) -> Iterator["TOMLDocument"]:
def secure(self) -> Iterator[TOMLDocument]:
if self.file.exists():
initial_config = self.file.read()
config = self.file.read()
Expand Down
7 changes: 3 additions & 4 deletions src/poetry/config/source.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import dataclasses
from __future__ import annotations

from typing import Dict
from typing import Union
import dataclasses


@dataclasses.dataclass(order=True, eq=True)
Expand All @@ -11,5 +10,5 @@ class Source:
default: bool = dataclasses.field(default=False)
secondary: bool = dataclasses.field(default=False)

def to_dict(self) -> Dict[str, Union[str, bool]]:
def to_dict(self) -> dict[str, str | bool]:
return dataclasses.asdict(self)
40 changes: 20 additions & 20 deletions src/poetry/console/application.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

import logging
import re

Expand All @@ -6,8 +8,6 @@
from typing import TYPE_CHECKING
from typing import Any
from typing import Callable
from typing import Optional
from typing import Type
from typing import cast

from cleo.application import Application as BaseApplication
Expand Down Expand Up @@ -37,7 +37,7 @@


def load_command(name: str) -> Callable:
def _load() -> Type[Command]:
def _load() -> type[Command]:
words = name.split(" ")
module = import_module("poetry.console.commands." + ".".join(words))
command_class = getattr(module, "".join(c.title() for c in words) + "Command")
Expand Down Expand Up @@ -94,7 +94,7 @@ def __init__(self) -> None:
super().__init__("poetry", __version__)

self._poetry = None
self._io: Optional["IO"] = None
self._io: IO | None = None
self._disable_plugins = False
self._plugins_loaded = False

Expand All @@ -108,7 +108,7 @@ def __init__(self) -> None:
self.set_command_loader(command_loader)

@property
def poetry(self) -> "Poetry":
def poetry(self) -> Poetry:
from pathlib import Path

from poetry.factory import Factory
Expand All @@ -131,10 +131,10 @@ def reset_poetry(self) -> None:

def create_io(
self,
input: Optional["Input"] = None,
output: Optional["Output"] = None,
error_output: Optional["Output"] = None,
) -> "IO":
input: Input | None = None,
output: Output | None = None,
error_output: Output | None = None,
) -> IO:
io = super().create_io(input, output, error_output)

# Set our own CLI styles
Expand All @@ -159,21 +159,21 @@ def create_io(

return io

def render_error(self, error: Exception, io: "IO") -> None:
def render_error(self, error: Exception, io: IO) -> None:
# We set the solution provider repository here to load providers
# only when an error occurs
self.set_solution_provider_repository(self._get_solution_provider_repository())

super().render_error(error, io)

def _run(self, io: "IO") -> int:
def _run(self, io: IO) -> int:
self._disable_plugins = io.input.parameter_option("--no-plugins")

self._load_plugins(io)

return super()._run(io)

def _configure_io(self, io: "IO") -> None:
def _configure_io(self, io: IO) -> None:
# We need to check if the command being run
# is the "run" command.
definition = self.definition
Expand Down Expand Up @@ -210,7 +210,7 @@ def _configure_io(self, io: "IO") -> None:
return super()._configure_io(io)

def register_command_loggers(
self, event: "ConsoleCommandEvent", event_name: str, _: Any
self, event: ConsoleCommandEvent, event_name: str, _: Any
) -> None:
from poetry.console.logging.io_formatter import IOFormatter
from poetry.console.logging.io_handler import IOHandler
Expand Down Expand Up @@ -251,7 +251,7 @@ def register_command_loggers(
logger.setLevel(level)

def configure_env(
self, event: "ConsoleCommandEvent", event_name: str, _: Any
self, event: ConsoleCommandEvent, event_name: str, _: Any
) -> None:
from poetry.console.commands.env_command import EnvCommand

Expand All @@ -276,11 +276,11 @@ def configure_env(
command.set_env(env)

def configure_installer(
self, event: "ConsoleCommandEvent", event_name: str, _: Any
self, event: ConsoleCommandEvent, event_name: str, _: Any
) -> None:
from poetry.console.commands.installer_command import InstallerCommand

command: "InstallerCommand" = cast(InstallerCommand, event.command)
command: InstallerCommand = cast(InstallerCommand, event.command)
if not isinstance(command, InstallerCommand):
return

Expand All @@ -291,7 +291,7 @@ def configure_installer(

self._configure_installer(command, event.io)

def _configure_installer(self, command: "InstallerCommand", io: "IO") -> None:
def _configure_installer(self, command: InstallerCommand, io: IO) -> None:
from poetry.installation.installer import Installer

poetry = command.poetry
Expand All @@ -306,7 +306,7 @@ def _configure_installer(self, command: "InstallerCommand", io: "IO") -> None:
installer.use_executor(poetry.config.get("experimental.new-installer", False))
command.set_installer(installer)

def _load_plugins(self, io: "IO") -> None:
def _load_plugins(self, io: IO) -> None:
if self._plugins_loaded:
return

Expand All @@ -322,7 +322,7 @@ def _load_plugins(self, io: "IO") -> None:
self._plugins_loaded = True

@property
def _default_definition(self) -> "Definition":
def _default_definition(self) -> Definition:
from cleo.io.inputs.option import Option

definition = super()._default_definition
Expand All @@ -333,7 +333,7 @@ def _default_definition(self) -> "Definition":

return definition

def _get_solution_provider_repository(self) -> "SolutionProviderRepository":
def _get_solution_provider_repository(self) -> SolutionProviderRepository:
from crashtest.solution_providers.solution_provider_repository import (
SolutionProviderRepository,
)
Expand Down
2 changes: 2 additions & 0 deletions src/poetry/console/command_loader.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

from typing import Callable

from cleo.exceptions import LogicException
Expand Down
2 changes: 2 additions & 0 deletions src/poetry/console/commands/about.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

from poetry.console.commands.command import Command


Expand Down
10 changes: 5 additions & 5 deletions src/poetry/console/commands/add.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from __future__ import annotations

import contextlib

from typing import Dict
from typing import List
from typing import cast

from cleo.helpers import argument
Expand Down Expand Up @@ -246,8 +246,8 @@ def handle(self) -> int:
return status

def get_existing_packages_from_input(
self, packages: List[str], section: Dict
) -> List[str]:
self, packages: list[str], section: dict
) -> list[str]:
existing_packages = []

for name in packages:
Expand All @@ -257,7 +257,7 @@ def get_existing_packages_from_input(

return existing_packages

def notify_about_existing_packages(self, existing_packages: List[str]) -> None:
def notify_about_existing_packages(self, existing_packages: list[str]) -> None:
self.line(
"The following packages are already present in the pyproject.toml and will"
" be skipped:\n"
Expand Down
Loading

0 comments on commit da9680b

Please sign in to comment.