Skip to content

chore: add encoding= to open() and type hints (4 files)#2

Open
mangodxd wants to merge 1 commit intomalinkang:mainfrom
mangodxd:cleanup/fix-py-issues-d9ab814d
Open

chore: add encoding= to open() and type hints (4 files)#2
mangodxd wants to merge 1 commit intomalinkang:mainfrom
mangodxd:cleanup/fix-py-issues-d9ab814d

Conversation

@mangodxd
Copy link
Copy Markdown

@mangodxd mangodxd commented Apr 5, 2026

Hello,

I noticed a few areas where the code could be made a bit more robust and readable. This PR focuses on minor housekeeping tasks and does not change any of the existing runtime logic:

Explicit encoding for file operations

  • notion_helper.py: added encoding="utf-8" to 1 open() call(s)

I added explicit encoding here because Python's default behavior depends on the operating system. This change ensures the code handles text consistently whether it is running on Windows, Linux, or macOS, preventing potential UnicodeDecodeErrors.

Type hint additions

  • duolingo.py: added type hints to 6 function(s)
  • notion_helper.py: added type hints to 13 function(s)
  • update_heatmap.py: added type hints to 1 function(s)
  • utils.py: added type hints to 29 function(s)

I have added basic type annotations based on variable names and default values. This should make the code easier to work with in modern IDEs without changing any of the actual logic.

Examples of changes

Example change in duolingo.py:

-def get_lastest():
+def get_lastest() -> tuple:
-def check_exist(id):
+def check_exist(id) -> None:
-def get_mistakes(id):
+def get_mistakes(id) -> None:
-def get_user_data():
+def get_user_data() -> None:
-def get_duolingo_data():
+def get_duolingo_data() -> None:
-def add_to_notion(xp, date, is_update, page_id):
+def add_to_notion(xp, date, is_update: bool, page_id: int) -> None:

Example change in notion_helper.py:

-    def write_database_id(self, database_id):
+    def write_database_id(self, database_id: int) -> None:
-        with open(env_file, "a") as file:
+        with open(env_file, "a", encoding="utf-8") as file:
-    def search_database(self, block_id):
+    def search_database(self, block_id: int) -> None:
-    def update_heatmap(self, block_id, url):
+    def update_heatmap(self, block_id: int, url: str):
-    def get_relation_id(self, name, id, icon, properties={}):
+    def get_relation_id(self, name: str, id, icon, properties: dict={}):
-    def update_book_page(self, page_id, properties):
+    def update_book_page(self, page_id: int, properties):
... (truncated for brevity)

Safety and verification

  • I verified these changes using ast.parse() to ensure no syntax errors were introduced.
  • Files using dynamic patterns like eval() or globals() were automatically skipped.
  • I did not modify any __init__.py files.

If any of these annotations look off to you, feel free to adjust them or close the PR entirely.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant