Skip to content

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

Open
mangodxd wants to merge 1 commit intoGPT-AGI:mainfrom
mangodxd:cleanup/fix-py-issues-49acd26a
Open

chore: add encoding= to open() and type hints (9 files)#9
mangodxd wants to merge 1 commit intoGPT-AGI:mainfrom
mangodxd:cleanup/fix-py-issues-49acd26a

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

  • session.py: added encoding="utf-8" to 2 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

  • anthropic_provider.py: added type hints to 3 function(s)
  • base.py: added type hints to 2 function(s)
  • cli.py: added type hints to 4 function(s)
  • conversation.py: added type hints to 5 function(s)
  • core.py: added type hints to 14 function(s)
  • minimax_provider.py: added type hints to 3 function(s)
  • openai_compatible.py: added type hints to 2 function(s)
  • query_engine.py: added type hints to 1 function(s)
  • session.py: added type hints to 1 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 anthropic_provider.py:

-            def __init__(self, *args, **kwargs):
+            def __init__(self, *args: list, **kwargs: dict):
-        **kwargs
+        **kwargs: dict
-        **kwargs
+        **kwargs: dict

Example change in base.py:

-        **kwargs
+        **kwargs: dict
-        **kwargs
+        **kwargs: dict

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.

I hope these small improvements are helpful for the project.

@GPT-AGI
Copy link
Copy Markdown
Owner

GPT-AGI commented Apr 5, 2026

Thanks for the PR — really appreciate the cleanup work.

I’d suggest splitting this into two smaller PRs:

  • PR A: keep only the encoding="utf-8" changes in session.py

    • This is low-risk and useful for cross-platform consistency, so I’d be happy to merge it quickly.
  • PR B: revise the type hints before resubmitting

    • *args: list is not correct for *args (it should usually be *args: Any)
    • **kwargs: dict is too broad / often misleading for dynamic passthrough (prefer **kwargs: Any, or precise types where semantics are clear)
    • For provider-facing methods, I’d prefer fewer but more accurate annotations rather than broad mechanical changes

I’d be less eager to take broad type-hint changes in dynamic provider methods unless the annotations are very precise.
Thanks again for the contribution — happy to review a follow-up PR.

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.

2 participants