Bladeren bron

add bugbear

Falko Schindler 1 jaar geleden
bovenliggende
commit
b0359e0439

+ 2 - 2
examples/simpy/async_realtime_environment.py

@@ -98,11 +98,11 @@ class AsyncRealtimeEnvironment(RealtimeEnvironment):
                 await self.step()
                 await self.step()
         except StopSimulation as exc:
         except StopSimulation as exc:
             return exc.args[0]  # == until.value
             return exc.args[0]  # == until.value
-        except EmptySchedule:
+        except EmptySchedule as e:
             if until is not None:
             if until is not None:
                 assert not until.triggered
                 assert not until.triggered
                 raise RuntimeError(
                 raise RuntimeError(
                     f'No scheduled events left but "until" event was not '
                     f'No scheduled events left but "until" event was not '
                     f'triggered: {until}'
                     f'triggered: {until}'
-                )
+                ) from e
         return None
         return None

+ 3 - 3
nicegui/element.py

@@ -105,9 +105,9 @@ class Element(Visibility):
 
 
     def __init_subclass__(cls, *,
     def __init_subclass__(cls, *,
                           component: Union[str, Path, None] = None,
                           component: Union[str, Path, None] = None,
-                          libraries: List[Union[str, Path]] = [],
-                          exposed_libraries: List[Union[str, Path]] = [],
-                          extra_libraries: List[Union[str, Path]] = [],
+                          libraries: List[Union[str, Path]] = [],  # noqa: B006
+                          exposed_libraries: List[Union[str, Path]] = [],  # noqa: B006
+                          extra_libraries: List[Union[str, Path]] = [],  # noqa: B006
                           ) -> None:
                           ) -> None:
         super().__init_subclass__()
         super().__init_subclass__()
         base = Path(inspect.getfile(cls)).parent
         base = Path(inspect.getfile(cls)).parent

+ 3 - 3
nicegui/elements/aggrid.py

@@ -17,7 +17,7 @@ class AgGrid(Element, component='aggrid.js', libraries=['lib/aggrid/ag-grid-comm
 
 
     def __init__(self,
     def __init__(self,
                  options: Dict, *,
                  options: Dict, *,
-                 html_columns: List[int] = [],
+                 html_columns: List[int] = [],  # noqa: B006
                  theme: str = 'balham',
                  theme: str = 'balham',
                  auto_size_columns: bool = True,
                  auto_size_columns: bool = True,
                  ) -> None:
                  ) -> None:
@@ -34,7 +34,7 @@ class AgGrid(Element, component='aggrid.js', libraries=['lib/aggrid/ag-grid-comm
         """
         """
         super().__init__()
         super().__init__()
         self._props['options'] = options
         self._props['options'] = options
-        self._props['html_columns'] = html_columns
+        self._props['html_columns'] = html_columns[:]
         self._props['auto_size_columns'] = auto_size_columns
         self._props['auto_size_columns'] = auto_size_columns
         self._classes.append('nicegui-aggrid')
         self._classes.append('nicegui-aggrid')
         self._classes.append(f'ag-theme-{theme}')
         self._classes.append(f'ag-theme-{theme}')
@@ -44,7 +44,7 @@ class AgGrid(Element, component='aggrid.js', libraries=['lib/aggrid/ag-grid-comm
                     df: 'pd.DataFrame', *,
                     df: 'pd.DataFrame', *,
                     theme: str = 'balham',
                     theme: str = 'balham',
                     auto_size_columns: bool = True,
                     auto_size_columns: bool = True,
-                    options: Dict = {}) -> Self:
+                    options: Dict = {}) -> Self:  # noqa: B006
         """Create an AG Grid from a Pandas DataFrame.
         """Create an AG Grid from a Pandas DataFrame.
 
 
         Note:
         Note:

+ 2 - 2
nicegui/elements/interactive_image.py

@@ -28,7 +28,7 @@ class InteractiveImage(SourceElement, ContentElement, component='interactive_ima
                  content: str = '',
                  content: str = '',
                  size: Optional[Tuple[float, float]] = None,
                  size: Optional[Tuple[float, float]] = None,
                  on_mouse: Optional[Callable[..., Any]] = None,
                  on_mouse: Optional[Callable[..., Any]] = None,
-                 events: List[str] = ['click'],
+                 events: List[str] = ['click'],  # noqa: B006
                  cross: Union[bool, str] = False,
                  cross: Union[bool, str] = False,
                  ) -> None:
                  ) -> None:
         """Interactive Image
         """Interactive Image
@@ -58,7 +58,7 @@ class InteractiveImage(SourceElement, ContentElement, component='interactive_ima
         :param on_pointer: callback for pointer events (contains image coordinates `image_x` and `image_y` in pixels, and `type` of the event)
         :param on_pointer: callback for pointer events (contains image coordinates `image_x` and `image_y` in pixels, and `type` of the event)
         """
         """
         super().__init__(source=source, content=content)
         super().__init__(source=source, content=content)
-        self._props['events'] = events
+        self._props['events'] = events[:]
         self._props['cross'] = cross
         self._props['cross'] = cross
         self._props['size'] = size
         self._props['size'] = size
 
 

+ 3 - 3
nicegui/elements/keyboard.py

@@ -21,8 +21,8 @@ class Keyboard(Element, component='keyboard.js'):
                  on_key: Optional[Callable[..., Any]] = None, *,
                  on_key: Optional[Callable[..., Any]] = None, *,
                  active: bool = True,
                  active: bool = True,
                  repeating: bool = True,
                  repeating: bool = True,
-                 ignore: List[Literal['input', 'select', 'button', 'textarea']] = [
-                     'input', 'select', 'button', 'textarea'],
+                 ignore: List[Literal['input', 'select', 'button', 'textarea']] =
+                     ['input', 'select', 'button', 'textarea'],  # noqa: B006
                  ) -> None:
                  ) -> None:
         """Keyboard
         """Keyboard
 
 
@@ -38,7 +38,7 @@ class Keyboard(Element, component='keyboard.js'):
         self.active = active
         self.active = active
         self._props['events'] = ['keydown', 'keyup']
         self._props['events'] = ['keydown', 'keyup']
         self._props['repeating'] = repeating
         self._props['repeating'] = repeating
-        self._props['ignore'] = ignore
+        self._props['ignore'] = ignore[:]
         self.on('key', self._handle_key)
         self.on('key', self._handle_key)
 
 
     def _handle_key(self, e: GenericEventArguments) -> None:
     def _handle_key(self, e: GenericEventArguments) -> None:

+ 2 - 2
nicegui/elements/leaflet.py

@@ -24,7 +24,7 @@ class Leaflet(Element, component='leaflet.js'):
                  center: Tuple[float, float] = (0.0, 0.0),
                  center: Tuple[float, float] = (0.0, 0.0),
                  zoom: int = 13,
                  zoom: int = 13,
                  *,
                  *,
-                 options: Dict = {},
+                 options: Dict = {},  # noqa: B006
                  draw_control: Union[bool, Dict] = False,
                  draw_control: Union[bool, Dict] = False,
                  ) -> None:
                  ) -> None:
         """Leaflet map
         """Leaflet map
@@ -47,7 +47,7 @@ class Leaflet(Element, component='leaflet.js'):
         self.zoom = zoom
         self.zoom = zoom
         self._props['center'] = center
         self._props['center'] = center
         self._props['zoom'] = zoom
         self._props['zoom'] = zoom
-        self._props['options'] = options
+        self._props['options'] = {**options}
         self._props['draw_control'] = draw_control
         self._props['draw_control'] = draw_control
 
 
         self.on('init', self._handle_init)
         self.on('init', self._handle_init)

+ 5 - 2
nicegui/elements/markdown.py

@@ -11,7 +11,10 @@ from .mixins.content_element import ContentElement
 
 
 class Markdown(ContentElement, component='markdown.js'):
 class Markdown(ContentElement, component='markdown.js'):
 
 
-    def __init__(self, content: str = '', *, extras: List[str] = ['fenced-code-blocks', 'tables']) -> None:
+    def __init__(self,
+                 content: str = '', *,
+                 extras: List[str] = ['fenced-code-blocks', 'tables'],  # noqa: B006
+                 ) -> None:
         """Markdown Element
         """Markdown Element
 
 
         Renders Markdown onto the page.
         Renders Markdown onto the page.
@@ -19,7 +22,7 @@ class Markdown(ContentElement, component='markdown.js'):
         :param content: the Markdown content to be displayed
         :param content: the Markdown content to be displayed
         :param extras: list of `markdown2 extensions <https://github.com/trentm/python-markdown2/wiki/Extras#implemented-extras>`_ (default: `['fenced-code-blocks', 'tables']`)
         :param extras: list of `markdown2 extensions <https://github.com/trentm/python-markdown2/wiki/Extras#implemented-extras>`_ (default: `['fenced-code-blocks', 'tables']`)
         """
         """
-        self.extras = extras
+        self.extras = extras[:]
         super().__init__(content=content)
         super().__init__(content=content)
         self._classes.append('nicegui-markdown')
         self._classes.append('nicegui-markdown')
         self._props['codehilite_css'] = (
         self._props['codehilite_css'] = (

+ 1 - 1
nicegui/observables.py

@@ -7,7 +7,7 @@ from typing import Any, Callable, Collection, Dict, Iterable, List, Optional, Su
 from . import events
 from . import events
 
 
 
 
-class ObservableCollection(abc.ABC):
+class ObservableCollection(abc.ABC):  # noqa: B024
 
 
     def __init__(self, *,
     def __init__(self, *,
                  factory: Callable,
                  factory: Callable,

+ 1 - 1
nicegui/testing/screen.py

@@ -44,7 +44,7 @@ class Screen:
         """Check if the browser is open."""
         """Check if the browser is open."""
         # https://stackoverflow.com/a/66150779/3419103
         # https://stackoverflow.com/a/66150779/3419103
         try:
         try:
-            self.selenium.current_url  # pylint: disable=pointless-statement
+            self.selenium.current_url  # pylint: disable=pointless-statement # noqa: B018
             return True
             return True
         except Exception as e:
         except Exception as e:
             print(e)
             print(e)

+ 3 - 1
pyproject.toml

@@ -81,10 +81,12 @@ indent-width = 4
 line-length = 120
 line-length = 120
 
 
 [tool.ruff.lint]
 [tool.ruff.lint]
-# See complete list: https://beta.ruff.rs/docs/rules
+# See complete list: https://docs.astral.sh/ruff/rules/
 select = [
 select = [
     "I",  # isort
     "I",  # isort
     "E",  # pycodestyle
     "E",  # pycodestyle
+    "W",  # pycodestyle
+    "B",  # bugbear
     "F",  # pyflakes
     "F",  # pyflakes
     "UP", # pyupgrade
     "UP", # pyupgrade
 ]
 ]