From cdd1bda87d1af5049c8548f1afccc181452d481f Mon Sep 17 00:00:00 2001 From: Jinge Li <9894243+chinapandaman@users.noreply.github.com> Date: Wed, 10 Jul 2024 22:48:42 +0000 Subject: [PATCH 01/10] PPF-688: add pyright rules --- pyrightconfig.json | 14 ++++++++++++++ requirements.txt | 1 + 2 files changed, 15 insertions(+) create mode 100644 pyrightconfig.json diff --git a/pyrightconfig.json b/pyrightconfig.json new file mode 100644 index 00000000..c57de8f7 --- /dev/null +++ b/pyrightconfig.json @@ -0,0 +1,14 @@ +{ + "typeCheckingMode": "basic", + "reportArgumentType": "none", + "reportAssignmentType": "none", + "reportAttributeAccessIssue": "none", + "reportReturnType": "none", + "reportOptionalSubscript": "none", + "reportIndexIssue": "none", + "reportOperatorIssue": "none", + "reportGeneralTypeIssues": "none", + "reportOptionalMemberAccess": "none", + // custom configs + "reportPossiblyUnboundVariable": true, +} diff --git a/requirements.txt b/requirements.txt index e67401ac..2457a2c3 100644 --- a/requirements.txt +++ b/requirements.txt @@ -6,6 +6,7 @@ pillow pudb pylint pypdf +pyright pytest reportlab requests From b473ea8cfe834e6801f004b70cefcdc04c3a7c78 Mon Sep 17 00:00:00 2001 From: Jinge Li <9894243+chinapandaman@users.noreply.github.com> Date: Wed, 10 Jul 2024 22:52:34 +0000 Subject: [PATCH 02/10] PPF-688: add linting script --- Makefile | 3 +++ scripts/linting.sh | 6 ++++++ 2 files changed, 9 insertions(+) create mode 100644 scripts/linting.sh diff --git a/Makefile b/Makefile index 62c4b1f3..27bdc671 100644 --- a/Makefile +++ b/Makefile @@ -10,6 +10,9 @@ coverage-all: check-imports: bash ./scripts/check_imports.sh +linting: + bash ./scripts/linting.sh + generate-new-pdf-samples: bash ./scripts/new_pdf_samples.sh diff --git a/scripts/linting.sh b/scripts/linting.sh new file mode 100644 index 00000000..949023fb --- /dev/null +++ b/scripts/linting.sh @@ -0,0 +1,6 @@ +if [[ "$VIRTUAL_ENV" == "" ]]; then + source "./venv/bin/activate" +fi + +pylint PyPDFForm/ +pyright . From 911a268533f99dbbfdc3d038fa43a6c7f4b50605 Mon Sep 17 00:00:00 2001 From: Jinge Li <9894243+chinapandaman@users.noreply.github.com> Date: Wed, 10 Jul 2024 22:56:29 +0000 Subject: [PATCH 03/10] PPF-688: remove check imports script --- Makefile | 3 --- pyrightconfig.json | 3 ++- scripts/check_imports.sh | 6 ------ 3 files changed, 2 insertions(+), 10 deletions(-) delete mode 100644 scripts/check_imports.sh diff --git a/Makefile b/Makefile index 27bdc671..1bd4d747 100644 --- a/Makefile +++ b/Makefile @@ -7,9 +7,6 @@ test-all: coverage-all: bash ./scripts/coverage.sh -check-imports: - bash ./scripts/check_imports.sh - linting: bash ./scripts/linting.sh diff --git a/pyrightconfig.json b/pyrightconfig.json index c57de8f7..58922674 100644 --- a/pyrightconfig.json +++ b/pyrightconfig.json @@ -10,5 +10,6 @@ "reportGeneralTypeIssues": "none", "reportOptionalMemberAccess": "none", // custom configs - "reportPossiblyUnboundVariable": true, + "reportPossiblyUnboundVariable": "error", + "reportUnusedImport": "error" } diff --git a/scripts/check_imports.sh b/scripts/check_imports.sh deleted file mode 100644 index af2c9e10..00000000 --- a/scripts/check_imports.sh +++ /dev/null @@ -1,6 +0,0 @@ -if [[ "$VIRTUAL_ENV" == "" ]]; then - source "./venv/bin/activate" -fi - -pylint ./tests | { grep "unused-import" || true; } -pylint ./PyPDFForm | { grep "unused-import" || true; } From 48af2fd75d2b079e1653478d9678eaa449094c2b Mon Sep 17 00:00:00 2001 From: Jinge Li <9894243+chinapandaman@users.noreply.github.com> Date: Wed, 10 Jul 2024 22:58:40 +0000 Subject: [PATCH 04/10] PPF-688: fix unused imports --- PyPDFForm/__init__.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/PyPDFForm/__init__.py b/PyPDFForm/__init__.py index 93151d17..01db70ab 100644 --- a/PyPDFForm/__init__.py +++ b/PyPDFForm/__init__.py @@ -4,3 +4,5 @@ __version__ = "1.4.30" from .wrapper import FormWrapper, PdfWrapper + +__all__ = ["FormWrapper", "PdfWrapper"] From e2c56073ec4f54903713d8cea9fa5b13c330796c Mon Sep 17 00:00:00 2001 From: Jinge Li <9894243+chinapandaman@users.noreply.github.com> Date: Wed, 10 Jul 2024 23:07:36 +0000 Subject: [PATCH 05/10] PPF-688: add more rules --- pyrightconfig.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pyrightconfig.json b/pyrightconfig.json index 58922674..ebf649ae 100644 --- a/pyrightconfig.json +++ b/pyrightconfig.json @@ -11,5 +11,6 @@ "reportOptionalMemberAccess": "none", // custom configs "reportPossiblyUnboundVariable": "error", - "reportUnusedImport": "error" + "reportUnusedImport": "error", + "reportIncompatibleMethodOverride": "error", } From 42ae476020ec8ca513d37d25933db2e6388adf9b Mon Sep 17 00:00:00 2001 From: Jinge Li <9894243+chinapandaman@users.noreply.github.com> Date: Thu, 11 Jul 2024 00:12:53 +0000 Subject: [PATCH 06/10] PPF-688: fix type hint --- PyPDFForm/middleware/checkbox.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/PyPDFForm/middleware/checkbox.py b/PyPDFForm/middleware/checkbox.py index 468d4ea2..a0b403f7 100644 --- a/PyPDFForm/middleware/checkbox.py +++ b/PyPDFForm/middleware/checkbox.py @@ -34,7 +34,7 @@ def schema_definition(self) -> dict: return {"type": "boolean"} @property - def sample_value(self) -> bool: + def sample_value(self) -> bool | int: """Sample value of the checkbox.""" return True From f4be505843c8fe29bd392609273dc7b05aecf7e0 Mon Sep 17 00:00:00 2001 From: Jinge Li <9894243+chinapandaman@users.noreply.github.com> Date: Thu, 11 Jul 2024 00:14:19 +0000 Subject: [PATCH 07/10] PPF-688: add rule for init --- PyPDFForm/middleware/base.py | 1 + PyPDFForm/widgets/base.py | 1 + PyPDFForm/wrapper.py | 1 + pyrightconfig.json | 1 + 4 files changed, 4 insertions(+) diff --git a/PyPDFForm/middleware/base.py b/PyPDFForm/middleware/base.py index 8a3f64fc..ca8eac6b 100644 --- a/PyPDFForm/middleware/base.py +++ b/PyPDFForm/middleware/base.py @@ -14,6 +14,7 @@ def __init__( ) -> None: """Constructs basic attributes for the object.""" + super().__init__() self._name = name self.value = value diff --git a/PyPDFForm/widgets/base.py b/PyPDFForm/widgets/base.py index 67541b73..8e0e4c71 100644 --- a/PyPDFForm/widgets/base.py +++ b/PyPDFForm/widgets/base.py @@ -29,6 +29,7 @@ def __init__( ) -> None: """Sets acro form parameters.""" + super().__init__() self.page_number = page_number self.acro_form_params = { "name": name, diff --git a/PyPDFForm/wrapper.py b/PyPDFForm/wrapper.py index 4f05146d..a5f1ccd5 100644 --- a/PyPDFForm/wrapper.py +++ b/PyPDFForm/wrapper.py @@ -36,6 +36,7 @@ def __init__( ) -> None: """Constructs all attributes for the object.""" + super().__init__() self.stream = fp_or_f_obj_or_stream_to_stream(template) def read(self) -> bytes: diff --git a/pyrightconfig.json b/pyrightconfig.json index ebf649ae..6f88cf30 100644 --- a/pyrightconfig.json +++ b/pyrightconfig.json @@ -13,4 +13,5 @@ "reportPossiblyUnboundVariable": "error", "reportUnusedImport": "error", "reportIncompatibleMethodOverride": "error", + "reportMissingSuperCall": "error" } From fdd8f6e386528cfb96a852c436c28a28a217ee0a Mon Sep 17 00:00:00 2001 From: Jinge Li <9894243+chinapandaman@users.noreply.github.com> Date: Thu, 11 Jul 2024 00:38:35 +0000 Subject: [PATCH 08/10] PPF-688: add ruff --- requirements.txt | 1 + ruff.toml | 2 ++ scripts/linting.sh | 1 + 3 files changed, 4 insertions(+) create mode 100644 ruff.toml diff --git a/requirements.txt b/requirements.txt index 2457a2c3..65895922 100644 --- a/requirements.txt +++ b/requirements.txt @@ -10,3 +10,4 @@ pyright pytest reportlab requests +ruff diff --git a/ruff.toml b/ruff.toml new file mode 100644 index 00000000..84d24170 --- /dev/null +++ b/ruff.toml @@ -0,0 +1,2 @@ +[lint] +select = ["E4", "E7", "E9", "F", "N802"] diff --git a/scripts/linting.sh b/scripts/linting.sh index 949023fb..94dbdaee 100644 --- a/scripts/linting.sh +++ b/scripts/linting.sh @@ -4,3 +4,4 @@ fi pylint PyPDFForm/ pyright . +ruff check . From 5314c71d89d64264a3a35334002f03e566319172 Mon Sep 17 00:00:00 2001 From: Jinge Li <9894243+chinapandaman@users.noreply.github.com> Date: Thu, 11 Jul 2024 00:41:22 +0000 Subject: [PATCH 09/10] PPF-688: update linting action --- .github/workflows/python-linting.yml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/.github/workflows/python-linting.yml b/.github/workflows/python-linting.yml index c2f6180a..08df8e09 100644 --- a/.github/workflows/python-linting.yml +++ b/.github/workflows/python-linting.yml @@ -24,3 +24,9 @@ jobs: - name: Analyze code with pylint run: | pylint PyPDFForm + - name: Analyze code with pyright + run: | + pyright . + - name: Analyze code with ruff + run: | + ruff check . From c0372877a72f00661243782e384bb090af6f2562 Mon Sep 17 00:00:00 2001 From: Jinge Li <9894243+chinapandaman@users.noreply.github.com> Date: Thu, 11 Jul 2024 00:45:06 +0000 Subject: [PATCH 10/10] PPF-688: back to old syntax --- PyPDFForm/middleware/checkbox.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/PyPDFForm/middleware/checkbox.py b/PyPDFForm/middleware/checkbox.py index a0b403f7..1a4609ab 100644 --- a/PyPDFForm/middleware/checkbox.py +++ b/PyPDFForm/middleware/checkbox.py @@ -34,7 +34,7 @@ def schema_definition(self) -> dict: return {"type": "boolean"} @property - def sample_value(self) -> bool | int: + def sample_value(self) -> Union[bool, int]: """Sample value of the checkbox.""" return True