1+ from __future__ import annotations
2+
13import random
24import socket
35import string
810from subprocess import PIPE , Popen , check_call
911from threading import Thread
1012from types import TracebackType
11- from typing import IO , Dict , Iterator , List , Optional , Sequence , Type , cast
13+ from typing import IO , Iterator , Sequence , cast
1214
1315from .version import __version__
1416
1517
1618class Index :
17- def __init__ (self , base_url : str , name : str , user : str , client_cmd_base : List [str ]) -> None :
19+ def __init__ (self , base_url : str , name : str , user : str , client_cmd_base : list [str ]) -> None :
1820 self ._client_cmd_base = client_cmd_base
1921 self ._server_url = base_url
2022 self .name = name
@@ -36,7 +38,7 @@ def __repr__(self) -> str:
3638
3739
3840class IndexServer :
39- def __init__ (self , path : Path , with_root_pypi : bool = False , start_args : Optional [ Sequence [str ]] = None ) -> None :
41+ def __init__ (self , path : Path , with_root_pypi : bool = False , start_args : Sequence [str ] | None = None ) -> None :
4042 self .path = path
4143 self ._with_root_pypi = with_root_pypi
4244 self ._start_args : Sequence [str ] = [] if start_args is None else start_args
@@ -57,16 +59,16 @@ def _exe(name: str) -> str:
5759
5860 self ._server_dir = self .path / "server"
5961 self ._client_dir = self .path / "client"
60- self ._indexes : Dict [str , Index ] = {}
61- self ._process : Optional [ " Popen[str]" ] = None
62+ self ._indexes : dict [str , Index ] = {}
63+ self ._process : Popen [str ] | None = None
6264 self ._has_use = False
63- self ._stdout_drain : Optional [ Thread ] = None
65+ self ._stdout_drain : Thread | None = None
6466
6567 @property
6668 def user (self ) -> str :
6769 return "root"
6870
69- def __enter__ (self ) -> " IndexServer" :
71+ def __enter__ (self ) -> IndexServer :
7072 self ._create_and_start_server ()
7173 self ._setup_client ()
7274 return self
@@ -124,9 +126,9 @@ def create_index(self, name: str, *args: str) -> Index:
124126
125127 def __exit__ (
126128 self ,
127- exc_type : Optional [ Type [ BaseException ]] , # noqa: U100
128- exc_val : Optional [ BaseException ] , # noqa: U100
129- exc_tb : Optional [ TracebackType ] , # noqa: U100
129+ exc_type : type [ BaseException ] | None , # noqa: U100
130+ exc_val : BaseException | None , # noqa: U100
131+ exc_tb : TracebackType | None , # noqa: U100
130132 ) -> None :
131133 if self ._process is not None : # pragma: no cover # defend against devpi startup fail
132134 self ._process .terminate ()
0 commit comments