Skip to content

Comments

Fix some missing type information#358

Open
cmdremily wants to merge 1 commit intoTeekeks:masterfrom
cmdremily:master
Open

Fix some missing type information#358
cmdremily wants to merge 1 commit intoTeekeks:masterfrom
cmdremily:master

Conversation

@cmdremily
Copy link

What

This is a first stab at completing type information for pyTwitchAPI. As this is my first contribution, I'm limiting this to low hanging fruit and a few of the files. If all goes well I'll do more.

Also add explicit python version to setup.py based on comments about what the minimum version is in README.md.

Why

When using pyTwitchAPI in my project with mypy I get errors due to missing type information in pyTwitchAPI.

How

I repeatedly ran mypy --strict . from the project root and fixed easy, unmistakable missing type annotations, mainly on return types.

@cmdremily cmdremily force-pushed the master branch 3 times, most recently from 12d6c19 to 5e4f5aa Compare February 4, 2026 07:53

@staticmethod
def _parse_irc_source(raw_source_component: str):
def _parse_irc_source(raw_source_component: str) -> dict[str, Optional[str]]:
Copy link
Contributor

Choose a reason for hiding this comment

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

If supporting 3.7+ then this needs to be Dict from typing and not builtin dict

Copy link
Author

Choose a reason for hiding this comment

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

Fixed.

}

async def _build_request_header(self) -> dict:
async def _build_request_header(self) -> dict[str,str]:
Copy link
Contributor

Choose a reason for hiding this comment

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

If supporting 3.7+ then this needs to be Dict from typing and not builtin dict

Copy link
Author

Choose a reason for hiding this comment

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

Fixed.

self.username: Optional[str] = None

def __await__(self):
def __await__(self) -> Generator[Any, Any, 'Chat']:
Copy link
Contributor

Choose a reason for hiding this comment

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

Should probably be Generator[Any, None, "Chat"]

Copy link
Author

Choose a reason for hiding this comment

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

Fixed.

@cmdremily
Copy link
Author

I should note that I added .python-version locally to 3.7, which made pip install -r requirements.txt fail since there is no version of aiohttp>=3.9.3 that supports Python 3.7, The 3.9 series seem to require Python 3.8 or later. For now, I'm not going to address that in his PR, but it seems like Python 3.8 is the actually required version based on the dependency above.

@Teekeks
Copy link
Owner

Teekeks commented Feb 5, 2026

I planned on dropping 3.7 compatibility with the next major release at the latest anyway since that python version is now long EOL. Not entirely sure which to target for now though. 3.10 would make sence as its the oldes version thats not EOL yet.

@cmdremily
Copy link
Author

Python 3.10 SGTM, should I change the version strings in this PR? Or is this good to merge as is?

@Teekeks
Copy link
Owner

Teekeks commented Feb 6, 2026

merge as is for now, gonna have to take a look if I want to go straight to 3.11 if I have to drop support rn anyway. And the change would not fit this PR anyway.

self.logger.debug('eventsub shut down')

def _get_transport(self) -> dict:
def _get_transport(self) -> dict[str,str]:
Copy link
Owner

Choose a reason for hiding this comment

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

this should also be Dict[str, str] like the other one

Copy link
Author

Choose a reason for hiding this comment

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

Done.

This is a first stab at completing type information for pyTwitchAPI to make mypy shut up when I'm using pyTwitchAPI. As this is my first contribution, I'm limiting this to low hanging fruit and a few of the files. If all goes well I'll do more.

Signed-off-by: Cmdr. Emily <68452184+cmdremily@users.noreply.github.com>
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.

3 participants