Skip to content

Commit

Permalink
Add type annotation for ContextWeakrefMixin
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 692904388
  • Loading branch information
oprypin authored and copybara-github committed Nov 4, 2024
1 parent e777112 commit 3ae24b5
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions pytype/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,14 @@
import keyword
import threading
import traceback
from typing import TYPE_CHECKING
import weakref

from pytype.platform_utils import path_utils

if TYPE_CHECKING:
from pytype import context # pylint: disable=g-bad-import-order,g-import-not-at-top

_STYLE_BRIGHT = "\x1b[1m"
_STYLE_RESET_ALL = "\x1b[0m"
_FORE_RED = "\x1b[31m"
Expand Down Expand Up @@ -236,9 +240,9 @@ class ContextWeakrefMixin:

__slots__ = ["ctx_weakref"]

def __init__(self, ctx):
def __init__(self, ctx: "context.Context"):
self.ctx_weakref = weakref.ref(ctx)

@property
def ctx(self):
return self.ctx_weakref()
def ctx(self) -> "context.Context":
return self.ctx_weakref() # pytype: disable=bad-return-type

0 comments on commit 3ae24b5

Please sign in to comment.