Skip to content

add more types #1222

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

Merged
merged 3 commits into from
Jul 7, 2025
Merged

add more types #1222

merged 3 commits into from
Jul 7, 2025

Conversation

aw-was-here
Copy link
Collaborator

@aw-was-here aw-was-here commented Jul 7, 2025

Summary by Sourcery

Enhancements:

  • Annotate function and method parameters and return types in upgrade, subprocesses, upgradeutils, bootstrap, settingsui, main, config, exceptions, frozen, and hostmeta modules

Copy link

sourcery-ai bot commented Jul 7, 2025

Reviewer's Guide

This PR systematically introduces PEP 484/PEP 604 type hints throughout the codebase—annotating parameters, return types, union types, and container types—while applying minor logic refinements for clarity and consistency.

Class diagram for updated type annotations in UpgradeDialog, UpgradeConfig, UpgradeTemplates, and Version

classDiagram
    class UpgradeDialog {
        __init__(parent: QWidget | None = None)
        fill_it_in(oldversion: nowplaying.upgradeutils.Version, newversion: nowplaying.upgradeutils.Version) -> None
    }
    class UpgradeConfig {
        __init__(testdir: str | pathlib.Path | None = None)
        _getconfig() -> QSettings
        backup_config() -> None
        upgrade() -> None
        _oldkey_to_newkey(oldconfig: QSettings, newconfig: QSettings, mapping: dict[str, str]) -> None
    }
    class UpgradeTemplates {
        copied: list[str]
        oldshas: dict[str, dict[str, str]]
        __init__(bundledir: str | pathlib.Path | None = None, testdir: str | pathlib.Path | None = None)
        preload() -> None
        check_preload(filename: str, userhash: str) -> str | None
        setup_templates() -> None
        _process_template_directory(app_dir: str | pathlib.Path, user_dir: pathlib.Path) -> None
    }
    class Version {
        __init__(version: str)
        _calculate() -> None
        is_prerelease() -> bool
        __str__() -> str
        __lt__(other: t.Any) -> bool
        __le__(other: t.Any) -> bool
        __eq__(other: t.Any) -> bool
        __ne__(other: t.Any) -> bool
        __hash__() -> int
        __gt__(other: t.Any) -> bool
        __ge__(other: t.Any) -> bool
    }
Loading

Class diagram for SubprocessManager with updated type annotations

classDiagram
    class SubprocessManager {
        config: nowplaying.config.ConfigFile | None
        testmode: bool
        processes: dict[str, dict[str, t.Any]]
        __init__(config: nowplaying.config.ConfigFile | None = None, testmode: bool = False)
        start_all_processes(startup_window: 'nowplaying.startup.StartupWindow')
        stop_all_processes() -> None
        _start_process(processname: str) -> None
        _stop_process_parallel(processname: str) -> None
        _stop_process(processname: str) -> None
        start_process(processname: str) -> None
        stop_process(processname: str) -> None
        restart_process(processname: str) -> None
        start_webserver() -> None
        start_kickbot() -> None
        start_twitchbot() -> None
        stop_webserver() -> None
        stop_twitchbot() -> None
        stop_kickbot() -> None
        restart_webserver() -> None
        restart_obsws() -> None
        restart_kickbot() -> None
    }
Loading

Class diagram for PluginVerifyError with updated type annotation

classDiagram
    class PluginVerifyError {
        message: str | None
        __init__(message: str | None = None)
    }
Loading

File-Level Changes

Change Details Files
Add PEP 484/PEP 604 type annotations to function and method signatures
  • Annotate constructors and methods with explicit parameter and return types
  • Use union syntax (X
None) for optional parameters
  • Specify Qt and pathlib types in signatures
  • Introduce typed container declarations for attributes and JSON data
    • Declare list[str] and dict[str, dict[str, str]] for instance attributes
    • Annotate JSON response and upgrade-data variables with list[dict[str, Any]] and dict[str, Any]
    nowplaying/upgrade.py
    nowplaying/subprocesses.py
    nowplaying/upgradeutils.py
    nowplaying/settingsui.py
    Refine minor logic expressions and membership tests
    • Simplify rotation flag assignment using bool(...)
    • Adjust Version.gt to use >= and != for clarity
    • Switch membership test to set literal for 'twitchbot'
    nowplaying/bootstrap.py
    nowplaying/upgradeutils.py
    nowplaying/subprocesses.py

    Tips and commands

    Interacting with Sourcery

    • Trigger a new review: Comment @sourcery-ai review on the pull request.
    • Continue discussions: Reply directly to Sourcery's review comments.
    • Generate a GitHub issue from a review comment: Ask Sourcery to create an
      issue from a review comment by replying to it. You can also reply to a
      review comment with @sourcery-ai issue to create an issue from it.
    • Generate a pull request title: Write @sourcery-ai anywhere in the pull
      request title to generate a title at any time. You can also comment
      @sourcery-ai title on the pull request to (re-)generate the title at any time.
    • Generate a pull request summary: Write @sourcery-ai summary anywhere in
      the pull request body to generate a PR summary at any time exactly where you
      want it. You can also comment @sourcery-ai summary on the pull request to
      (re-)generate the summary at any time.
    • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
      request to (re-)generate the reviewer's guide at any time.
    • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
      pull request to resolve all Sourcery comments. Useful if you've already
      addressed all the comments and don't want to see them anymore.
    • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
      request to dismiss all existing Sourcery reviews. Especially useful if you
      want to start fresh with a new review - don't forget to comment
      @sourcery-ai review to trigger a new review!

    Customizing Your Experience

    Access your dashboard to:

    • Enable or disable review features such as the Sourcery-generated pull request
      summary, the reviewer's guide, and others.
    • Change the review language.
    • Add, remove or edit custom review instructions.
    • Adjust other review settings.

    Getting Help

    Copy link

    @sourcery-ai sourcery-ai bot left a comment

    Choose a reason for hiding this comment

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

    Hey @aw-was-here - I've reviewed your changes and found some issues that need to be addressed.

    Blocking issues:

    • The new gt implementation may cause incorrect results. (link)
    Prompt for AI Agents
    Please address the comments from this code review:
    ## Individual Comments
    
    ### Comment 1
    <location> `nowplaying/upgradeutils.py:119` </location>
    <code_context>
                          self.chunk.get('rc'),
                          self.chunk.get('commitnum')))
    
    -    def __gt__(self, other):
    +    def __gt__(self, other: t.Any) -> bool:
             ''' version greater than '''
    -        return not (self < other or self == other)
    </code_context>
    
    <issue_to_address>
    The new __gt__ implementation may cause incorrect results.
    
    Using 'self >= other and self != other' creates logical inconsistencies and risks infinite recursion, as __ge__ and __gt__ may call each other. Please revert to the standard implementation to ensure correct behavior.
    </issue_to_address>
    
    ### Comment 2
    <location> `nowplaying/upgradeutils.py:124` </location>
    <code_context>
    +        return self >= other and self != other
    
    -    def __ge__(self, other):
    +    def __ge__(self, other: t.Any) -> bool:
             ''' version greater than or equal '''
             return self == other or self > other
    </code_context>
    
    <issue_to_address>
    The __ge__ method implementation can cause infinite recursion.
    
    Mutual recursion between __ge__ and __gt__ can cause a stack overflow. Please refactor to prevent this.
    </issue_to_address>
    
    ### Comment 3
    <location> `nowplaying/bootstrap.py:47` </location>
    <code_context>
         app.setApplicationName(appname)
    
    
    -def setuplogging(logdir=None, logname='debug.log', rotate=False):
    +def setuplogging(logdir: pathlib.Path | str | None = None,
    +                 logname: str ='debug.log',
    +                 rotate: bool = False) -> pathlib.Path:
    </code_context>
    
    <issue_to_address>
    The besuretorotate variable is redundant.
    
    Since besuretorotate is assigned but never used, please remove it to clean up the code.
    
    Suggested implementation:
    
    ```python
        if logdir:
            logpath = pathlib.Path(logdir)
            if logpath.is_file():
                logpath.mkdir(parents=True, exist_ok=True)
            logfile = logpath.joinpath(logname)
    
    ```
    
    If there is a line in the function assigning `besuretorotate = ...`, it should be removed as well. Since the provided code snippet does not show such a line, please ensure that any assignment to `besuretorotate` within the full function is deleted.
    </issue_to_address>

    Sourcery is free for open source - if you like our reviews please consider sharing them ✨
    Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

    @aw-was-here aw-was-here merged commit efab6d3 into main Jul 7, 2025
    13 checks passed
    @aw-was-here aw-was-here deleted the aw/more_types branch July 7, 2025 04:58
    Copy link

    codecov bot commented Jul 7, 2025

    Codecov Report

    Attention: Patch coverage is 98.55072% with 1 line in your changes missing coverage. Please review.

    Project coverage is 66.68%. Comparing base (c608c9e) to head (7feb48c).
    Report is 1 commits behind head on main.

    Files with missing lines Patch % Lines
    nowplaying/settingsui.py 75.00% 1 Missing ⚠️
    Additional details and impacted files

    Impacted file tree graph

    @@            Coverage Diff             @@
    ##             main    #1222      +/-   ##
    ==========================================
    - Coverage   66.69%   66.68%   -0.02%     
    ==========================================
      Files          68       68              
      Lines       11522    11527       +5     
    ==========================================
    + Hits         7685     7687       +2     
    - Misses       3837     3840       +3     
    Flag Coverage Δ
    unittests 66.68% <98.55%> (-0.02%) ⬇️

    Flags with carried forward coverage won't be shown. Click here to find out more.

    Files with missing lines Coverage Δ
    nowplaying/__main__.py 94.73% <100.00%> (+0.29%) ⬆️
    nowplaying/bootstrap.py 61.53% <100.00%> (+0.42%) ⬆️
    nowplaying/config.py 88.23% <ø> (ø)
    nowplaying/exceptions.py 100.00% <100.00%> (ø)
    nowplaying/frozen.py 58.33% <100.00%> (ø)
    nowplaying/hostmeta.py 96.66% <100.00%> (ø)
    nowplaying/subprocesses.py 80.53% <100.00%> (+0.53%) ⬆️
    nowplaying/upgrade.py 71.48% <100.00%> (-0.13%) ⬇️
    nowplaying/upgradeutils.py 87.85% <100.00%> (+0.11%) ⬆️
    nowplaying/settingsui.py 69.93% <75.00%> (-0.02%) ⬇️

    ... and 2 files with indirect coverage changes

    🚀 New features to boost your workflow:
    • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

    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.

    1 participant