Skip to content

fix: update type hints#29

Draft
Olegt0rr wants to merge 1 commit intodpnspn:mainfrom
Olegt0rr:fix-typing
Draft

fix: update type hints#29
Olegt0rr wants to merge 1 commit intodpnspn:mainfrom
Olegt0rr:fix-typing

Conversation

@Olegt0rr
Copy link
Copy Markdown

@Olegt0rr Olegt0rr commented Feb 9, 2026

Updated some type hints

Copilot AI review requested due to automatic review settings February 9, 2026 14:57
self.name: str | None = None
self.description: str | None = None
self.bot_commands: list[BotCommand] = None
self.bot_commands: list[BotCommand] | None = None
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need default None here?
Looks like default should be [ ]

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates type hints across the aiomax library to better reflect actual runtime values (notably timestamps and optional returns), and fixes a small typo in an attachment error message.

Changes:

  • Annotate message payload builders and bot/router state with more explicit types.
  • Adjust timestamp-related attributes to float-based seconds and make several APIs return Message | None.
  • Fix typo in an attachment validation error string.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 10 comments.

File Description
aiomax/utils.py Adds Any and types the constructed message body dict; fixes an error-message typo.
aiomax/types.py Updates various timestamp/value type hints and several from_json / message-related return types.
aiomax/router.py Adds an explicit optional type for parent.
aiomax/bot.py Types session and bot_commands as optional.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +41 to 43
self.last_activity_time: float | None = (
last_activity_time / 1000 if last_activity_time else None
)
Copy link

Copilot AI Feb 9, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

float | None is a PEP 604 union and will be evaluated at runtime; this raises on Python 3.9. Use a quoted annotation or Optional[float] here. Also, last_access_time is still annotated as int | None but is computed via / 1000, which produces a float—its annotation should be updated for consistency.

Copilot uses AI. Check for mistakes.
Comment on lines 54 to 56
self.is_admin: "bool | None" = is_admin
self.join_time: "int | None" = join_time / 1000 if join_time else None
self.join_time: "float | None" = join_time / 1000 if join_time else None
self.permissions: "list[str] | None" = permissions
Copy link

Copilot AI Feb 9, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

float | None is a PEP 604 union and will be evaluated at runtime; this raises on Python 3.9. Use a quoted annotation or Optional[float] for join_time (or bump the minimum Python version).

Copilot uses AI. Check for mistakes.
Comment on lines +555 to 557
def from_json(data: dict) -> "LinkedMessage | None":
if data is None:
return None
Copy link

Copilot AI Feb 9, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

data can be None (the function explicitly handles that), but the parameter is typed as dict. Update the signature to accept dict | None (or equivalent) so callers like data.get(...) type-check cleanly.

Copilot uses AI. Check for mistakes.
self.type: str = type
self.status: str = status
self.last_event_time: int = (
self.last_event_time: float | None = (
Copy link

Copilot AI Feb 9, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

float | None is a PEP 604 union and will be evaluated at runtime; this raises on Python 3.9. Use a quoted annotation or Optional[float] for last_event_time (or bump the minimum Python version).

Suggested change
self.last_event_time: float | None = (
self.last_event_time: Optional[float] = (

Copilot uses AI. Check for mistakes.
] = {} # commands in this router
self.case_sensitive: bool = case_sensitive
self.parent = None # Parent bot of this router
self.parent: Router | None = None # Parent bot of this router
Copy link

Copilot AI Feb 9, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

self.parent: Router | None uses PEP 604 unions, which are evaluated at runtime and will raise on Python 3.9 (the project declares requires-python >= 3.9). Use a quoted annotation (e.g. "Router | None") or Optional[Router] to keep 3.9 compatibility (or bump the minimum Python version if 3.10+ is required).

Suggested change
self.parent: Router | None = None # Parent bot of this router
self.parent: Optional["Router"] = None # Parent bot of this router

Copilot uses AI. Check for mistakes.
] = {} # commands in this router
self.case_sensitive: bool = case_sensitive
self.parent = None # Parent bot of this router
self.parent: Router | None = None # Parent bot of this router
Copy link

Copilot AI Feb 9, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The inline comment says “Parent bot of this router”, but parent is typed/used as a parent router (and can be a Bot only in the root case). Update the comment to reflect what parent actually represents to avoid confusion when working with nested routers.

Suggested change
self.parent: Router | None = None # Parent bot of this router
self.parent: Router | None = None # Parent router in the hierarchy (may be the bot for the root router)

Copilot uses AI. Check for mistakes.

self.access_token: str = access_token
self.session = None
self.session: aiohttp.ClientSession | None = None
Copy link

Copilot AI Feb 9, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

aiohttp.ClientSession | None is a PEP 604 union and will be evaluated at runtime; this raises on Python 3.9. Since the project targets 3.9+, use a quoted annotation or Optional[aiohttp.ClientSession] (or raise the minimum supported Python version).

Copilot uses AI. Check for mistakes.
self.name: str | None = None
self.description: str | None = None
self.bot_commands: list[BotCommand] = None
self.bot_commands: list[BotCommand] | None = None
Copy link

Copilot AI Feb 9, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

list[BotCommand] | None is a PEP 604 union and will be evaluated at runtime; this raises on Python 3.9. Use a quoted annotation or Optional[list[BotCommand]] (or bump requires-python to 3.10+).

Copilot uses AI. Check for mistakes.

@staticmethod
def from_json(data: dict) -> "MessageRecipient":
def from_json(data: dict) -> "MessageRecipient | None":
Copy link

Copilot AI Feb 9, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

data can be None (the function explicitly handles that), but the parameter is typed as dict. Update the signature to accept dict | None (or equivalent) so callers like data.get(...) type-check cleanly.

Suggested change
def from_json(data: dict) -> "MessageRecipient | None":
def from_json(data: "dict | None") -> "MessageRecipient | None":

Copilot uses AI. Check for mistakes.
Comment on lines +526 to 528
def from_json(data: dict) -> "MessageBody | None":
if data is None:
return None
Copy link

Copilot AI Feb 9, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

data can be None (the function explicitly handles that), but the parameter is typed as dict. Update the signature to accept dict | None (or equivalent) so callers like data.get(...) type-check cleanly.

Copilot uses AI. Check for mistakes.
@Olegt0rr Olegt0rr marked this pull request as draft February 10, 2026 02:29
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