Browse Source

Fix typing compatibility for Python3.9

master
Gabriel Huber 5 months ago
parent
commit
b40eb24cdb
  1. 18
      a2s/info.py
  2. 10
      a2s/players.py
  3. 10
      a2s/rules.py
  4. 2
      setup.py

18
a2s/info.py

@ -1,6 +1,6 @@
import io import io
from dataclasses import dataclass from dataclasses import dataclass
from typing import Optional, Generic, TypeVar, overload from typing import Optional, Generic, Union, TypeVar, overload
from a2s.exceptions import BrokenMessageError, BufferExhaustedError from a2s.exceptions import BrokenMessageError, BufferExhaustedError
from a2s.defaults import DEFAULT_TIMEOUT, DEFAULT_ENCODING from a2s.defaults import DEFAULT_TIMEOUT, DEFAULT_ENCODING
@ -186,33 +186,33 @@ class GoldSrcInfo(Generic[StrType]):
@overload @overload
def info(address: tuple[str, int], timeout: float, encoding: str) -> SourceInfo[str] | GoldSrcInfo[str]: def info(address: tuple[str, int], timeout: float, encoding: str) -> Union[SourceInfo[str], GoldSrcInfo[str]]:
... ...
@overload @overload
def info(address: tuple[str, int], timeout: float, encoding: None) -> SourceInfo[bytes] | GoldSrcInfo[bytes]: def info(address: tuple[str, int], timeout: float, encoding: None) -> Union[SourceInfo[bytes], GoldSrcInfo[bytes]]:
... ...
def info( def info(
address: tuple[str, int], address: tuple[str, int],
timeout: float = DEFAULT_TIMEOUT, timeout: float = DEFAULT_TIMEOUT,
encoding: str | None = DEFAULT_ENCODING encoding: Union[str, None] = DEFAULT_ENCODING
) -> SourceInfo[str] | SourceInfo[bytes] | GoldSrcInfo[str] | GoldSrcInfo[bytes]: ) -> Union[SourceInfo[str], SourceInfo[bytes], GoldSrcInfo[str], GoldSrcInfo[bytes]]:
return request_sync(address, timeout, encoding, InfoProtocol) return request_sync(address, timeout, encoding, InfoProtocol)
@overload @overload
async def ainfo(address: tuple[str, int], timeout: float, encoding: str) -> SourceInfo[str] | GoldSrcInfo[str]: async def ainfo(address: tuple[str, int], timeout: float, encoding: str) -> Union[SourceInfo[str], GoldSrcInfo[str]]:
... ...
@overload @overload
async def ainfo(address: tuple[str, int], timeout: float, encoding: None) -> SourceInfo[bytes] | GoldSrcInfo[bytes]: async def ainfo(address: tuple[str, int], timeout: float, encoding: None) -> Union[SourceInfo[bytes], GoldSrcInfo[bytes]]:
... ...
async def ainfo( async def ainfo(
address: tuple[str, int], address: tuple[str, int],
timeout: float = DEFAULT_TIMEOUT, timeout: float = DEFAULT_TIMEOUT,
encoding: str | None = DEFAULT_ENCODING encoding: Union[str, None] = DEFAULT_ENCODING
) -> SourceInfo[str] | SourceInfo[bytes] | GoldSrcInfo[str] | GoldSrcInfo[bytes]: ) -> Union[SourceInfo[str], SourceInfo[bytes], GoldSrcInfo[str], GoldSrcInfo[bytes]]:
return await request_async(address, timeout, encoding, InfoProtocol) return await request_async(address, timeout, encoding, InfoProtocol)

10
a2s/players.py

@ -1,6 +1,6 @@
import io import io
from dataclasses import dataclass from dataclasses import dataclass
from typing import Generic, TypeVar, overload from typing import Generic, Union, TypeVar, overload
from a2s.defaults import DEFAULT_TIMEOUT, DEFAULT_ENCODING from a2s.defaults import DEFAULT_TIMEOUT, DEFAULT_ENCODING
from a2s.a2s_sync import request_sync from a2s.a2s_sync import request_sync
@ -40,8 +40,8 @@ def players(address: tuple[str, int], timeout: float, encoding: None) -> list[Pl
def players( def players(
address: tuple[str, int], address: tuple[str, int],
timeout: float = DEFAULT_TIMEOUT, timeout: float = DEFAULT_TIMEOUT,
encoding: str | None = DEFAULT_ENCODING encoding: Union[str, None] = DEFAULT_ENCODING
) -> list[Player[str]] | list[Player[bytes]]: ) -> Union[list[Player[str]], list[Player[bytes]]]:
return request_sync(address, timeout, encoding, PlayersProtocol) return request_sync(address, timeout, encoding, PlayersProtocol)
@overload @overload
@ -55,8 +55,8 @@ async def aplayers(address: tuple[str, int], timeout: float, encoding: None) ->
async def aplayers( async def aplayers(
address: tuple[str, int], address: tuple[str, int],
timeout: float = DEFAULT_TIMEOUT, timeout: float = DEFAULT_TIMEOUT,
encoding: str | None = DEFAULT_ENCODING encoding: Union[str, None] = DEFAULT_ENCODING
) -> list[Player[str]] | list[Player[bytes]]: ) -> Union[list[Player[str]], list[Player[bytes]]]:
return await request_async(address, timeout, encoding, PlayersProtocol) return await request_async(address, timeout, encoding, PlayersProtocol)

10
a2s/rules.py

@ -1,5 +1,5 @@
import io import io
from typing import overload from typing import overload, Union
from a2s.defaults import DEFAULT_TIMEOUT, DEFAULT_ENCODING from a2s.defaults import DEFAULT_TIMEOUT, DEFAULT_ENCODING
from a2s.a2s_sync import request_sync from a2s.a2s_sync import request_sync
@ -22,8 +22,8 @@ def rules(address: tuple[str, int], timeout: float, encoding: None) -> dict[byte
def rules( def rules(
address: tuple[str, int], address: tuple[str, int],
timeout: float = DEFAULT_TIMEOUT, timeout: float = DEFAULT_TIMEOUT,
encoding: str | None = DEFAULT_ENCODING encoding: Union[str, None] = DEFAULT_ENCODING
) -> dict[str, str] | dict[bytes, bytes]: ) -> Union[dict[str, str], dict[bytes, bytes]]:
return request_sync(address, timeout, encoding, RulesProtocol) return request_sync(address, timeout, encoding, RulesProtocol)
@overload @overload
@ -37,8 +37,8 @@ async def arules(address: tuple[str, int], timeout: float, encoding: None) -> di
async def arules( async def arules(
address: tuple[str, int], address: tuple[str, int],
timeout: float = DEFAULT_TIMEOUT, timeout: float = DEFAULT_TIMEOUT,
encoding: str | None = DEFAULT_ENCODING encoding: Union[str, None] = DEFAULT_ENCODING
) -> dict[str, str] | dict[bytes, bytes]: ) -> Union[dict[str, str], dict[bytes, bytes]]:
return await request_async(address, timeout, encoding, RulesProtocol) return await request_async(address, timeout, encoding, RulesProtocol)

2
setup.py

@ -7,7 +7,7 @@ with open("README.md", "r") as readme:
setuptools.setup( setuptools.setup(
name="python-a2s", name="python-a2s",
version="1.4.0", version="1.4.1",
author="Gabriel Huber", author="Gabriel Huber",
author_email="[email protected]", author_email="[email protected]",
description="Query Source and GoldSource servers for name, map, players and more.", description="Query Source and GoldSource servers for name, map, players and more.",

Loading…
Cancel
Save