Skip to content

Commit

Permalink
add pylint checks
Browse files Browse the repository at this point in the history
  • Loading branch information
falkoschindler committed Apr 11, 2024
1 parent 4c2d1b7 commit 7c3e01a
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 18 deletions.
4 changes: 2 additions & 2 deletions examples/search_as_you_type/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@


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
Expand Down
13 changes: 6 additions & 7 deletions examples/slideshow/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,21 @@

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()
4 changes: 2 additions & 2 deletions examples/trello_cards/draganddrop.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def unhighlight(self) -> None:
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:
Expand All @@ -50,5 +50,5 @@ def __init__(self, item: Item) -> None:
self.on('dragstart', self.handle_dragstart)

def handle_dragstart(self) -> None:
global dragged
global dragged # pylint: disable=global-statement # noqa: PLW0603
dragged = self
2 changes: 1 addition & 1 deletion nicegui/element.py
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ def default_classes(cls,
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()
Expand Down
5 changes: 2 additions & 3 deletions nicegui/elements/select.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ def __init__(self,
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 []
Expand All @@ -89,10 +88,10 @@ def _event_args_to_value(self, e: GenericEventArguments) -> Any:
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
Expand Down
6 changes: 6 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ select = [
"F", # pyflakes
"UP", # pyupgrade
"RUF", # ruff
"PL", # pylint
]
fixable = [
"I", # isort
Expand All @@ -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/*",
Expand Down
6 changes: 3 additions & 3 deletions tests/test_observables.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,17 @@


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

Expand Down

0 comments on commit 7c3e01a

Please sign in to comment.