Skip to content

Commit

Permalink
Turn mypy:no-any-return on
Browse files Browse the repository at this point in the history
The 'no-any-return' error code has been disabled before due to the code
not being ready for it. This patch delivers amends to the code base, and
enables the rule that must be enabled.
  • Loading branch information
ikalnytskyi committed Feb 10, 2024
1 parent d203943 commit cce7e80
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 13 deletions.
1 change: 0 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,6 @@ disable_error_code = [
"comparison-overlap",
"import-not-found",
"misc",
"no-any-return",
"no-untyped-call",
"no-untyped-def",
"type-arg",
Expand Down
9 changes: 3 additions & 6 deletions src/picobox/_stack.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,8 @@ def do(magic):
"""

def __init__(self, name: t.Optional[str] = None):
self._name = name
self._stack = []
self._name = name or "0x%x" % id(self)
self._stack: list[Box] = []
self._lock = threading.Lock()

# A proxy object that proxies all calls to a box instance on the top
Expand All @@ -108,10 +108,7 @@ def __init__(self, name: t.Optional[str] = None):
self._topbox = _create_stack_proxy(self._stack)

def __repr__(self):
name = self._name
if not self._name:
name = "0x%x" % id(self)
return "<Stack (%s)>" % name
return f"<Stack ({self._name})>"

def push(self, box: Box, *, chain: bool = False) -> t.ContextManager[Box]:
"""Push a :class:`Box` instance to the top of the stack.
Expand Down
10 changes: 7 additions & 3 deletions src/picobox/ext/asgiscopes.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,12 @@

import picobox

_current_app_store = contextvars.ContextVar(f"{__name__}.current-app-store")
_current_req_store = contextvars.ContextVar(f"{__name__}.current-req-store")
if t.TYPE_CHECKING:
Store = contextvars.ContextVar[weakref.WeakKeyDictionary]


_current_app_store: "Store" = contextvars.ContextVar(f"{__name__}.current-app-store")
_current_req_store: "Store" = contextvars.ContextVar(f"{__name__}.current-req-store")


class ScopeMiddleware:
Expand Down Expand Up @@ -52,7 +56,7 @@ async def __call__(self, scope, receive, send):
class _asgiscope(picobox.Scope):
"""A base class for ASGI scopes."""

_store_cvar: contextvars.ContextVar
_store_cvar: "Store"

@property
def _store(self) -> t.MutableMapping[t.Hashable, t.Any]:
Expand Down
8 changes: 5 additions & 3 deletions src/picobox/ext/wsgiscopes.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@
if t.TYPE_CHECKING:
from _typeshed.wsgi import StartResponse, WSGIApplication, WSGIEnvironment

Store = contextvars.ContextVar[weakref.WeakKeyDictionary]

_current_app_store = contextvars.ContextVar(f"{__name__}.current-app-store")
_current_req_store = contextvars.ContextVar(f"{__name__}.current-req-store")

_current_app_store: "Store" = contextvars.ContextVar(f"{__name__}.current-app-store")
_current_req_store: "Store" = contextvars.ContextVar(f"{__name__}.current-req-store")


class ScopeMiddleware:
Expand Down Expand Up @@ -61,7 +63,7 @@ def __call__(
class _wsgiscope(picobox.Scope):
"""A base class for WSGI scopes."""

_store_cvar: contextvars.ContextVar
_store_cvar: "Store"

@property
def _store(self) -> t.MutableMapping[t.Hashable, t.Any]:
Expand Down

0 comments on commit cce7e80

Please sign in to comment.