Skip to content

Commit

Permalink
Check for lints with ruff
Browse files Browse the repository at this point in the history
  • Loading branch information
yuvadm committed May 20, 2024
1 parent 4618fc4 commit ee6bb75
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 18 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,7 @@ jobs:
uses: abatilo/actions-poetry@v2
- name: Poetry install
run: poetry install
- name: Run build
- name: Run unit tests
run: poetry run pytest
- name: Check for lints
run: poetry run ruff check
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ python = "^3.8"

[tool.poetry.group.dev.dependencies]
pytest = "^8.2.1"
ruff = "^0.4.4"

[build-system]
requires = ["poetry-core"]
Expand Down
2 changes: 1 addition & 1 deletion tests/test_parse.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from datetime import datetime
from os import walk
from os.path import join
from viewstate import *
from viewstate import ViewState, ViewStateException


class TestParse(object):
Expand Down
4 changes: 2 additions & 2 deletions tests/test_viewstate.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from os import walk
from os.path import join
from viewstate import *
from viewstate import ViewState, ViewStateException


class TestViewState(object):
Expand All @@ -19,7 +19,7 @@ def test_is_valid(self):

def test_invalid_base64(self):
with pytest.raises(ViewStateException):
vs = ViewState("hello")
ViewState("hello")

def test_invalid_decode(self):
with pytest.raises(ViewStateException):
Expand Down
3 changes: 3 additions & 0 deletions viewstate/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
from .viewstate import ViewState
from .exceptions import ViewStateException


__all__ = [ViewState, ViewStateException]
24 changes: 12 additions & 12 deletions viewstate/parse.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,14 +181,14 @@ class StringArray(Parser):
@staticmethod
def parse(b):
n, remain = Integer.parse(b)
l = []
lst = []
for _ in range(n):
if not remain[0]:
val, remain = "", remain[1:]
else:
val, remain = String.parse(remain)
l.append(val)
return l, remain
lst.append(val)
return lst, remain


class Array(Parser):
Expand All @@ -197,11 +197,11 @@ class Array(Parser):
@staticmethod
def parse(b):
n, remain = Integer.parse(b)
l = []
lst = []
for _ in range(n):
val, remain = Parser.parse(remain)
l.append(val)
return l, remain
lst.append(val)
return lst, remain


class StringRef(Parser):
Expand Down Expand Up @@ -231,12 +231,12 @@ def parse(b):
type, remain = Parser.parse(b)
length, remain = Integer.parse(remain)
n, remain = Integer.parse(remain)
l = [None] * length
lst = [None] * length
for _ in range(n):
idx, remain = Integer.parse(remain)
val, remain = Parser.parse(remain)
l[idx] = val
return l, remain
lst[idx] = val
return lst, remain


class Dict(Parser):
Expand All @@ -261,11 +261,11 @@ class TypedArray(Parser):
def parse(b):
typeval, remain = Parser.parse(b)
n, remain = Integer.parse(remain)
l = []
lst = []
for _ in range(n):
val, remain = Parser.parse(remain)
l.append(val)
return l, remain
lst.append(val)
return lst, remain


class BinaryFormatted(Parser):
Expand Down
4 changes: 2 additions & 2 deletions viewstate/viewstate.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from base64 import b64decode, b64encode
from base64 import b64decode
from binascii import Error as BinAsciiError

from .exceptions import ViewStateException
Expand All @@ -11,7 +11,7 @@ def __init__(self, base64=None, raw=None):
self.base64 = base64
try:
self.raw = b64decode(self.base64)
except BinAsciiError as bae:
except BinAsciiError:
raise ViewStateException("Cannot decode base64 input")
elif raw:
self.raw = raw
Expand Down

0 comments on commit ee6bb75

Please sign in to comment.