Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: make typehinting for Extension.bot work #1748

Merged
merged 1 commit into from
Jan 3, 2025
Merged

Conversation

AstreaTSS
Copy link
Member

@AstreaTSS AstreaTSS commented Jan 2, 2025

Pull Request Type

  • Feature addition
  • Bugfix
  • Documentation update
  • Code refactor
  • Tests improvement
  • CI/CD pipeline enhancement
  • Other: [Replace with a description]

Description

This PR makes the typehint for Extension.bot correct when using Pyright. For some reason, doing bot: Client doesn't typehint the variable correctly in Pyright, and so this PR works around it by making bot and client properties with setters, which both makes it act like the old variable and also makes Pyright not complain... for some reason.

Perhaps further investigation can be done to see just why the original issue occurs, but at least this PR hides the issue from the typical user.

Changes

  • Make Extension.bot and Extension.client properties with setters.
    • The ability to set these two variables is intentional, to ensure nothing relying on that breaks.
    • This technically is a breaking change still due to some niche stuff with Python (properties are not variables, after all), but I'm not sure if those use cases were supported in the first place.

Related Issues

#1747

Test Scenarios

import interactions as ipy

class AnExt(ipy.Extension):
    def test(self):
        reveal_type(self.bot)  # "Unknown" before pr, "Client" after

Python Compatibility

  • I've ensured my code works on Python 3.10.x
  • I've ensured my code works on Python 3.11.x

Checklist

  • I've run the pre-commit code linter over all edited files
  • I've tested my changes on supported Python versions
  • I've added tests for my code, if applicable
  • I've updated / added documentation, where applicable

@silasary silasary merged commit 27fee39 into unstable Jan 3, 2025
9 of 12 checks passed
@silasary silasary deleted the make-ext-bot-work branch January 3, 2025 02:17
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