Browse Source

add pylint checks

Falko Schindler 1 year ago
parent
commit
7c3e01af16

+ 2 - 2
examples/search_as_you_type/main.py

@@ -11,8 +11,8 @@ running_query: Optional[asyncio.Task] = None
 
 
 async def search(e: events.ValueChangeEventArguments) -> None:
-    '''Search for cocktails as you type.'''
-    global running_query
+    """Search for cocktails as you type."""
+    global running_query  # pylint: disable=global-statement # noqa: PLW0603
     if running_query:
         running_query.cancel()  # cancel the previous query; happens when you type fast
     search_field.classes('mt-2', remove='mt-24')  # move the search field up

+ 6 - 7
examples/slideshow/main.py

@@ -8,22 +8,21 @@ ui.query('.nicegui-content').classes('p-0')  # remove padding from the main cont
 
 folder = Path(__file__).parent / 'slides'  # image source: https://pixabay.com/
 files = sorted(f.name for f in folder.glob('*.jpg'))
-index = 0
+state = {'index': 0}
 
 
 def handle_key(event: KeyEventArguments) -> None:
-    global index
     if event.action.keydown:
         if event.key.arrow_right:
-            index += 1
+            state['index'] += 1
         if event.key.arrow_left:
-            index -= 1
-        index = index % len(files)
-        slide.set_source(f'slides/{files[index]}')
+            state['index'] -= 1
+        state['index'] %= len(files)
+        slide.set_source(f'slides/{files[state["index"]]}')
 
 
 app.add_static_files('/slides', folder)  # serve all files in this folder
-slide = ui.image(f'slides/{files[index]}')  # show the first image
+slide = ui.image(f'slides/{files[state["index"]]}')  # show the first image
 ui.keyboard(on_key=handle_key)  # handle keyboard events
 
 ui.run()

+ 2 - 2
examples/trello_cards/draganddrop.py

@@ -31,7 +31,7 @@ class column(ui.column):
         self.classes(remove='bg-blue-grey-3', add='bg-blue-grey-2')
 
     def move_card(self) -> None:
-        global dragged
+        global dragged  # pylint: disable=global-statement # noqa: PLW0603
         self.unhighlight()
         dragged.parent_slot.parent.remove(dragged)
         with self:
@@ -50,5 +50,5 @@ class card(ui.card):
         self.on('dragstart', self.handle_dragstart)
 
     def handle_dragstart(self) -> None:
-        global dragged
+        global dragged  # pylint: disable=global-statement # noqa: PLW0603
         dragged = self

+ 1 - 1
nicegui/element.py

@@ -273,7 +273,7 @@ class Element(Visibility):
     def _parse_style(text: Optional[str]) -> Dict[str, str]:
         result = {}
         for word in (text or '').split(';'):
-            word = word.strip()
+            word = word.strip()  # noqa: PLW2901
             if word:
                 key, value = word.split(':', 1)
                 result[key.strip()] = value.strip()

+ 2 - 3
nicegui/elements/select.py

@@ -79,7 +79,6 @@ class Select(ValidationElement, ChoiceElement, DisableableElement, component='se
         self._props['clearable'] = clearable
 
     def _event_args_to_value(self, e: GenericEventArguments) -> Any:
-        # pylint: disable=no-else-return
         if self.multiple:
             if e.args is None:
                 return []
@@ -89,10 +88,10 @@ class Select(ValidationElement, ChoiceElement, DisableableElement, component='se
                     if isinstance(arg, str):
                         self._handle_new_value(arg)
                 return [arg for arg in args if arg in self._values]
-        else:
+        else:  # noqa: PLR5501
             if e.args is None:
                 return None
-            else:
+            else:  # noqa: PLR5501
                 if isinstance(e.args, str):
                     new_value = self._handle_new_value(e.args)
                     return new_value if new_value in self._values else None

+ 6 - 0
pyproject.toml

@@ -90,6 +90,7 @@ select = [
     "F",  # pyflakes
     "UP", # pyupgrade
     "RUF", # ruff
+    "PL", # pylint
 ]
 fixable = [
     "I",  # isort
@@ -98,6 +99,11 @@ ignore = [
     "E501", # line too long
     "UP006", # use pipe for union type annotation
     "UP007", # use pipe for union type annotation
+    "PLR0911", # too many return statements
+    "PLR0912", # too many branches
+    "PLR0913", # too many arguments
+    "PLR0915", # too many statements
+    "PLR2004", # magic value comparison
 ]
 exclude = [
     "website/documentation/content/*",

+ 3 - 3
tests/test_observables.py

@@ -10,17 +10,17 @@ count = 0
 
 
 def reset_counter():
-    global count
+    global count  # noqa: PLW0603
     count = 0
 
 
 def increment_counter():
-    global count
+    global count  # noqa: PLW0603
     count += 1
 
 
 async def increment_counter_slowly(_):
-    global count
+    global count  # noqa: PLW0603
     await asyncio.sleep(0.1)
     count += 1