Skip to content

Commit

Permalink
Add pragma on unreachable code from different OSs (encode#2036)
Browse files Browse the repository at this point in the history
* Add pragma on unreachable code from different OSs

* Update pyproject.toml

* Update pyproject.toml
  • Loading branch information
Kludex authored Jul 9, 2023
1 parent acbd088 commit d52db4c
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 13 deletions.
5 changes: 4 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ omit = [

[tool.coverage.report]
precision = 2
fail_under = 98.28
fail_under = 98.35
show_missing = true
skip_covered = true
exclude_lines = [
Expand All @@ -111,6 +111,7 @@ exclude_lines = [

[tool.coverage.coverage_conditional_plugin.omit]
"sys_platform == 'win32'" = ["uvicorn/loops/uvloop.py"]
"sys_platform != 'win32'" = ["uvicorn/loops/asyncio.py"]

[tool.coverage.coverage_conditional_plugin.rules]
py-win32 = "sys_platform == 'win32'"
Expand All @@ -121,3 +122,5 @@ py-gte-38 = "sys_version_info >= (3, 8)"
py-lt-38 = "sys_version_info < (3, 8)"
py-gte-39 = "sys_version_info >= (3, 9)"
py-lt-39 = "sys_version_info < (3, 9)"
py-gte-311 = "sys_version_info >= (3, 11)"
py-lt-311 = "sys_version_info < (3, 11)"
12 changes: 6 additions & 6 deletions uvicorn/_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,14 @@
Union,
)

if sys.version_info >= (3, 8):
if sys.version_info >= (3, 8): # pragma: py-lt-38
from typing import Literal, Protocol, TypedDict
else:
else: # pragma: py-gte-38
from typing_extensions import Literal, Protocol, TypedDict

if sys.version_info >= (3, 11):
if sys.version_info >= (3, 11): # pragma: py-lt-311
from typing import NotRequired
else:
else: # pragma: py-gte-311
from typing_extensions import NotRequired

# WSGI
Expand Down Expand Up @@ -261,12 +261,12 @@ class LifespanShutdownFailedEvent(TypedDict):

class ASGI2Protocol(Protocol):
def __init__(self, scope: Scope) -> None:
...
... # pragma: no cover

async def __call__(
self, receive: ASGIReceiveCallable, send: ASGISendCallable
) -> None:
...
... # pragma: no cover


ASGI2Application = Type[ASGI2Protocol]
Expand Down
2 changes: 1 addition & 1 deletion uvicorn/loops/asyncio.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@
logger = logging.getLogger("uvicorn.error")


def asyncio_setup(use_subprocess: bool = False) -> None: # pragma: no cover
def asyncio_setup(use_subprocess: bool = False) -> None:
if sys.platform == "win32" and use_subprocess:
asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy())
9 changes: 4 additions & 5 deletions uvicorn/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,12 +120,11 @@ def _share_socket(
sock_data = sock.share(os.getpid()) # type: ignore[attr-defined]
return fromshare(sock_data)

self.servers = []
self.servers: List[asyncio.base_events.Server] = []
for sock in sockets:
if config.workers > 1 and platform.system() == "Windows":
sock = _share_socket( # type: ignore[assignment]
sock
) # pragma py-linux pragma: py-darwin
is_windows = platform.system() == "Windows"
if config.workers > 1 and is_windows: # pragma: py-not-win32
sock = _share_socket(sock) # type: ignore[assignment]
server = await loop.create_server(
create_protocol, sock=sock, ssl=config.ssl, backlog=config.backlog
)
Expand Down

0 comments on commit d52db4c

Please sign in to comment.