Skip to content
Discussion options

You must be logged in to vote

The final line of the error message mypy gives you here says:

Singleton.py:36: note: (Hint: Use "x: Final = ..." or "x: ClassVar = ..." to define a class attribute)

In this case, that would mean doing this:

 import threading
-from typing import Any, Hashable, Type, TypeVar
+from typing import Any, Final, Hashable, Type, TypeVar

 T = TypeVar("T", bound="Singleton")

 class Singleton:
-    __instances: dict[Any, dict[Hashable, Any]] = {}        # L24
-    __singleton_lock = threading.Lock()                     # L25
+    __instances: Final[dict[Any, dict[Hashable, Any]]] = {}        # L24
+    __singleton_lock: Final = threading.Lock()                     # L25
     __singleton_id__: Hash…

Replies: 2 comments 3 replies

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
3 replies
@dineshbvadhia
Comment options

@AlexWaygood
Comment options

@dineshbvadhia
Comment options

Answer selected by dineshbvadhia
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants