Skip to content

Use "cls" instead of "self" in classmethod#2908

Merged
pplantinga merged 1 commit intospeechbrain:developfrom
rogiervd:pyright-cls
May 19, 2025
Merged

Use "cls" instead of "self" in classmethod#2908
pplantinga merged 1 commit intospeechbrain:developfrom
rogiervd:pyright-cls

Conversation

@rogiervd
Copy link
Contributor

What does this PR do?

In a classmethod, cls is normally used, not self.

This was flagged by Pyright (see #2901).

Before submitting
  • Did you read the contributor guideline?
  • Did you make sure your PR does only one thing, instead of bundling different changes together?
  • Did you make sure to update the documentation with your changes? (if necessary)
  • Did you write any new necessary tests? (not for typos and docs)
  • Did you verify new and existing tests pass locally with your changes?
  • Did you list all the breaking changes introduced by this pull request?
  • Does your code adhere to project-specific code style and conventions?

PR review

Reviewer checklist
  • Is this pull request ready for review? (if not, please submit in draft mode)
  • Check that all items from Before submitting are resolved
  • Make sure the title is self-explanatory and the description concisely explains the PR
  • Add labels and milestones (and optionally projects) to the PR so it can be classified
  • Confirm that the changes adhere to compatibility requirements (e.g., Python version, platform)
  • Review the self-review checklist to ensure the code is ready for review

Copy link
Collaborator

@pplantinga pplantinga left a comment

Choose a reason for hiding this comment

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

One minor comment, shouldn't the returned instance be created with the passed cls object (e.g. for subclassing) rather than CTCBeam directly?

Otherwise, LGTM

@rogiervd
Copy link
Contributor Author

Maybe, but this is a behaviour change so not what I tried to do here. It would require all subclasses of CTCBeam to have the same signature for the constructor, which it is not clear to me is desirable.

For the record, I think this is what the types would look like:

from typing import TypeVar, Type

Subclass = TypeVar('Subclass', bound='CTCBeam')

class CTCBeam:
    @classmethod
    def from_lm_beam(cls: Type[Subclass], lm_beam: "LMCTCBeam") -> Subclass:

@pplantinga
Copy link
Collaborator

Ah, well perhaps its better not to mess with it then. In that case LGTM

@pplantinga pplantinga merged commit c7ba0fe into speechbrain:develop May 19, 2025
5 checks passed
pplantinga pushed a commit to pplantinga/speechbrain that referenced this pull request Jun 2, 2025
Co-authored-by: Rogier van Dalen <r.vandalen@samsung.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.

2 participants