1
0
Эх сурвалжийг харах

add some missing type annotations

Falko Schindler 1 жил өмнө
parent
commit
7d23b0a606

+ 3 - 2
nicegui/client.py

@@ -11,6 +11,7 @@ from typing import TYPE_CHECKING, Any, Awaitable, Callable, Dict, Iterable, Iter
 from fastapi import Request
 from fastapi.responses import Response
 from fastapi.templating import Jinja2Templates
+from typing_extensions import Self
 
 from . import background_tasks, binding, core, helpers, json, outbox
 from .awaitable_response import AwaitableResponse
@@ -98,11 +99,11 @@ class Client:
         """Return the HTML code to be inserted in the <body> of the page template."""
         return self.shared_body_html + self._body_html
 
-    def __enter__(self):
+    def __enter__(self) -> Self:
         self.content.__enter__()
         return self
 
-    def __exit__(self, *_):
+    def __exit__(self, *_) -> None:
         self.content.__exit__()
 
     def build_response(self, request: Request, status_code: int = 200) -> Response:

+ 1 - 1
nicegui/element.py

@@ -161,7 +161,7 @@ class Element(Visibility):
         self.default_slot.__enter__()
         return self
 
-    def __exit__(self, *_):
+    def __exit__(self, *_) -> None:
         self.default_slot.__exit__(*_)
 
     def __iter__(self) -> Iterator[Element]:

+ 3 - 1
nicegui/elements/leaflet.py

@@ -1,6 +1,8 @@
 from pathlib import Path
 from typing import Any, List, Tuple, cast
 
+from typing_extensions import Self
+
 from .. import binding
 from ..awaitable_response import AwaitableResponse, NullResponse
 from ..element import Element
@@ -41,7 +43,7 @@ class Leaflet(Element, component='leaflet.js'):
             options={'attribution': '&copy; <a href="https://openstreetmap.org">OpenStreetMap</a> contributors'},
         )
 
-    def __enter__(self) -> 'Leaflet':
+    def __enter__(self) -> Self:
         Layer.current_leaflet = self
         return super().__enter__()
 

+ 4 - 2
nicegui/elements/pyplot.py

@@ -3,6 +3,8 @@ import io
 import os
 from typing import Any
 
+from typing_extensions import Self
+
 from .. import background_tasks, optional_features
 from ..client import Client
 from ..element import Element
@@ -41,11 +43,11 @@ class Pyplot(Element):
             self.fig.savefig(output, format='svg')
             self._props['innerHTML'] = output.getvalue()
 
-    def __enter__(self):
+    def __enter__(self) -> Self:
         plt.figure(self.fig)
         return self
 
-    def __exit__(self, *_):
+    def __exit__(self, *_) -> None:
         self._convert_to_html()
         if self.close:
             plt.close(self.fig)