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 invalid type hinting of initial_channels in WS Connection #461

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

junah201
Copy link

@junah201 junah201 commented Jul 2, 2024

Description

Resolve : #460

Checklist

  • If code changes were made then they have been tested.
    • I have updated the documentation to reflect the changes.
    • I have updated the changelog with a quick recap of my changes.
  • This PR fixes an issue.
  • This PR adds something new (e.g. new method or parameters).
  • This PR is a breaking change (e.g. methods or parameters removed/renamed)
  • This PR is not a code change (e.g. documentation, README, ...)
  • I have read and agree to the Developer Certificate of Origin for this contribution

Copy link
Collaborator

@chillymosh chillymosh left a comment

Choose a reason for hiding this comment

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

Please use the imports from the typing module instead of builtins. This version of TwitchIO has to support 3.8.
You have also removed the generic type of str.
This can also be None so you can add None inside the Union too.

You should also correct all other instances of this in client.py and bot.py

initial_channels: Union[List[str], Tuple[str, ...], Callable[[], Union[List[str], Tuple[str, ...]]], None] = None,

@junah201
Copy link
Author

junah201 commented Jul 3, 2024

@chillymosh Thank you for your feedback

I corrected all other instances.

I just wonder if the tuple[type] in the code below is okay?
I mainly use 3.10 version, so Im a little confused about what syntax is available in 3.8.

class UnionArgumentParsingFailed(ArgumentParsingFailed):
def __init__(self, argname: str, expected: tuple[type, ...]):
self.name: str = argname
self.expected_type: tuple[type, ...] = expected
self.message = f"Failed to convert argument `{self.name}` to any of the valid options"
Exception.__init__(self, self.message)

@IAmTomahawkx
Copy link
Member

IAmTomahawkx commented Jul 3, 2024

Our minimum supported version is 3.7, as such all changes should work on 3.7. You can download version 3.7 to verify these changes (or just tell pyright to use that version for type checking if using pyright, which is what we typically use).
tuple[...] is not valid in 3.7. You must use Tuple[...] using typing.Tuple.

Also to note: Version 2.x of twitchio does not follow strict type checking. Typing is used as hints through the code, not as a source of truth.

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.

Invalid type hinting in initial_channels
3 participants