Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Nov 29, 2025

ConnectionKeepAlive._emit_event() passes a data argument to event handlers, but the client handlers didn't accept it, causing TypeError: _on_keep_alive_connected() takes 1 positional argument but 2 were given.

Changes

  • _on_keep_alive_connected: Add data: Dict[str, Any] = None parameter
  • _on_keep_alive_reconnected: Add data: Dict[str, Any] = None parameter
  • _on_keep_alive_message: Change from message string to data dict, extract message via data.get("message", "")
# Before
async def _on_keep_alive_connected(self):
    ...

# After
async def _on_keep_alive_connected(self, data: Dict[str, Any] = None):
    ...

Fixes #43

Original prompt

This section details on the original issue you should resolve

<issue_title>ERROR: Event handler in client.py</issue_title>
<issue_description>Error in event handler for connected: AsyncPocketOptionClient._on_keep_alive_connected() takes 1 positional argument but 2 were given</issue_description>

Comments on the Issue (you are @copilot in this section)


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

@coderabbitai
Copy link

coderabbitai bot commented Nov 29, 2025

Important

Review skipped

Bot user detected.

To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.


Comment @coderabbitai help to get the list of available commands and usage tips.

…KeepAlive._emit_event()

Fixes issue #43: Error in event handler for connected:
AsyncPocketOptionClient._on_keep_alive_connected() takes 1 positional argument but 2 were given

Changed:
- _on_keep_alive_connected(self) -> _on_keep_alive_connected(self, data=None)
- _on_keep_alive_reconnected(self) -> _on_keep_alive_reconnected(self, data=None)
- _on_keep_alive_message(self, message) -> _on_keep_alive_message(self, data=None) with proper dict extraction

Co-authored-by: theshadow76 <59869868+theshadow76@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix error in event handler for connected Fix event handler signatures for keep-alive connection events Nov 29, 2025
Copilot AI requested a review from theshadow76 November 29, 2025 11:45
@theshadow76 theshadow76 marked this pull request as ready for review November 29, 2025 12:22
Copilot AI review requested due to automatic review settings November 29, 2025 12:22
@theshadow76 theshadow76 merged commit 237578a into main Nov 29, 2025
1 check passed
Copy link

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 fixes a critical bug where event handlers in AsyncPocketOptionClient had incorrect signatures, causing TypeError when called by ConnectionKeepAlive._emit_event(). The issue (#43) manifested as "takes 1 positional argument but 2 were given" errors because the handlers didn't accept the data parameter that _emit_event() always passes.

Key Changes:

  • Updated three event handler signatures to accept a data: Dict[str, Any] = None parameter
  • Modified _on_keep_alive_message to extract the message string from the data dictionary
  • Added comprehensive test suite to verify the fix and prevent regression

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
pocketoptionapi_async/client.py Fixed signatures of _on_keep_alive_connected, _on_keep_alive_reconnected, and _on_keep_alive_message to accept the data parameter passed by ConnectionKeepAlive._emit_event()
tests/test_event_handler_signatures.py Added comprehensive test suite covering all signature fixes, including edge cases, integration tests, and callback propagation verification

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

return candles

async def _on_keep_alive_connected(self):
async def _on_keep_alive_connected(self, data: Dict[str, Any] = None):
Copy link

Copilot AI Nov 29, 2025

Choose a reason for hiding this comment

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

The type hint should be Optional[Dict[str, Any]] instead of Dict[str, Any] since the default value is None. This properly indicates that the parameter can be either a dictionary or None.

async def _on_keep_alive_connected(self, data: Optional[Dict[str, Any]] = None):
Suggested change
async def _on_keep_alive_connected(self, data: Dict[str, Any] = None):
async def _on_keep_alive_connected(self, data: Optional[Dict[str, Any]] = None):

Copilot uses AI. Check for mistakes.
logger.error(f"Error in connected callback: {e}")

async def _on_keep_alive_reconnected(self):
async def _on_keep_alive_reconnected(self, data: Dict[str, Any] = None):
Copy link

Copilot AI Nov 29, 2025

Choose a reason for hiding this comment

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

The type hint should be Optional[Dict[str, Any]] instead of Dict[str, Any] since the default value is None. This properly indicates that the parameter can be either a dictionary or None.

async def _on_keep_alive_reconnected(self, data: Optional[Dict[str, Any]] = None):
Suggested change
async def _on_keep_alive_reconnected(self, data: Dict[str, Any] = None):
async def _on_keep_alive_reconnected(self, data: Optional[Dict[str, Any]] = None):

Copilot uses AI. Check for mistakes.
logger.error(f"Error in reconnected callback: {e}")

async def _on_keep_alive_message(self, message):
async def _on_keep_alive_message(self, data: Dict[str, Any] = None):
Copy link

Copilot AI Nov 29, 2025

Choose a reason for hiding this comment

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

The type hint should be Optional[Dict[str, Any]] instead of Dict[str, Any] since the default value is None. This properly indicates that the parameter can be either a dictionary or None.

async def _on_keep_alive_message(self, data: Optional[Dict[str, Any]] = None):
Suggested change
async def _on_keep_alive_message(self, data: Dict[str, Any] = None):
async def _on_keep_alive_message(self, data: Optional[Dict[str, Any]] = None):

Copilot uses AI. Check for mistakes.
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.

ERROR: Event handler in client.py

2 participants