Don't use mutable defaults for SCMClient methods.

Review Request #14471 — Created June 24, 2025 and updated

Information

RBTools
master

Reviewers

This change updates the parse_revision_spec, diff, and
create_commit methods for SCMClients to avoid using mutable lists as
defaults for arguments. These are now set to use
(Sequence[str] | None) = None, and initialize the values in the body
of the method instead.

Because all "real" call sites pass these in (as empty lists), I've
added deprecation warnings that we will be removing the default value
(and the | None) in rbtools 8.

Ran unit tests.

Summary ID
Don't use mutable defaults for SCMClient methods.
This change updates the `parse_revision_spec`, `diff`, and `create_commit` methods for SCMClients to avoid using mutable lists as defaults for arguments. These are now set to use `(Sequence[str] | None) = None`, and initialize the values in the body of the method instead. Because all "real" call sites pass these in (as empty lists), I've added deprecation warnings that we will be removing the default value (and the `| None`) in rbtools 8. Testing Done: Ran unit tests.
f4d05933ad0520da8f5ce34d9a9b67a699905a3d
Description From Last Updated

'typing.List' imported but unused Column: 1 Error code: F401

reviewbotreviewbot

'typing.List' imported but unused Column: 1 Error code: F401

reviewbotreviewbot

Why do we need to add | None here?

maubinmaubin

If calling the SCMClient's diff() directly, I think it's reasonable to be able to leave off these argument. I think …

chipx86chipx86

Should this assert, or should we fall back to a value? This might be called manually be a caller, not …

chipx86chipx86

Isn't the is not None check redundant since we check if its a dict right after?

maubinmaubin

'typing.Type' imported but unused Column: 1 Error code: F401

reviewbotreviewbot
Checks run (1 failed, 1 succeeded)
flake8 failed.
JSHint passed.

flake8

david
maubin
  1. 
      
  2. rbtools/clients/bazaar.py (Diff revision 2)
     
     
    Show all issues

    Why do we need to add | None here?

    1. It's just to bring it into sync with the signature of the method in the base class.

  3. rbtools/clients/bazaar.py (Diff revision 2)
     
     
     
     
     
     

    It would be nice to have a "This argument will be mandatory" thing in housekeeping. Not necessary for this change though.

  4. rbtools/clients/tests/__init__.py (Diff revision 2)
     
     
     
    Show all issues

    Isn't the is not None check redundant since we check if its a dict right after?

    1. Kinda sorta. type checkers don't seem to treat assertIsInstance the same as assert isinstance() when it comes to type narrowing.

    2. Yeah, no built-in support for that. Python doesn't have the right primitives for assertIsInstance (TypeIs and TypeGuard both impose some constraints on how the function operates that isn't right for assertIsInstance). Pretty annoying that this case isn't covered.

  5. 
      
maubin
  1. Ship It!
  2. 
      
chipx86
  1. This is overall good, but two things stand out:

    1. diff() is being treated as an internal function, with optional arguments now made mandatory. I don't think we should be doing this. This method can be called by utility scripts, and as those arguments aren't required for building a standard diff, I believe they should remain optional. (This would also mean undoing the unit test changes that pass in empty values so that we can make sure they remain optional).

    2. This makes changes to Plastic that are going to conflict with pending work on my end. Can we ignore this module for now?

  2. rbtools/clients/cvs.py (Diff revision 2)
     
     
     
     
     
     
     
     
     
     
     
     
     
     
    Show all issues

    If calling the SCMClient's diff() directly, I think it's reasonable to be able to leave off these argument. I think they should stay optional.

  3. rbtools/clients/perforce.py (Diff revision 2)
     
     
    Show all issues

    Should this assert, or should we fall back to a value? This might be called manually be a caller, not just internally.

  4. 
      
david
Review request changed
Commits:
Summary ID
Don't use mutable defaults for SCMClient methods.
This change updates the `parse_revision_spec`, `diff`, and `create_commit` methods for SCMClients to avoid using mutable lists as defaults for arguments. These are now set to use `(Sequence[str] | None) = None`, and initialize the values in the body of the method instead. Because all "real" call sites pass these in (as empty lists), I've added deprecation warnings that we will be removing the default value (and the `| None`) in rbtools 8. Testing Done: Ran unit tests.
c90a2de378ec581efb1f70e7e470abb1844ef5d5
Don't use mutable defaults for SCMClient methods.
This change updates the `parse_revision_spec`, `diff`, and `create_commit` methods for SCMClients to avoid using mutable lists as defaults for arguments. These are now set to use `(Sequence[str] | None) = None`, and initialize the values in the body of the method instead. Because all "real" call sites pass these in (as empty lists), I've added deprecation warnings that we will be removing the default value (and the `| None`) in rbtools 8. Testing Done: Ran unit tests.
d18d727f97c1c748d7233ed93d06cbf78e89101c

Checks run (1 failed, 1 succeeded)

flake8 failed.
JSHint passed.

flake8

david
Review request changed
Commits:
Summary ID
Don't use mutable defaults for SCMClient methods.
This change updates the `parse_revision_spec`, `diff`, and `create_commit` methods for SCMClients to avoid using mutable lists as defaults for arguments. These are now set to use `(Sequence[str] | None) = None`, and initialize the values in the body of the method instead. Because all "real" call sites pass these in (as empty lists), I've added deprecation warnings that we will be removing the default value (and the `| None`) in rbtools 8. Testing Done: Ran unit tests.
d18d727f97c1c748d7233ed93d06cbf78e89101c
Don't use mutable defaults for SCMClient methods.
This change updates the `parse_revision_spec`, `diff`, and `create_commit` methods for SCMClients to avoid using mutable lists as defaults for arguments. These are now set to use `(Sequence[str] | None) = None`, and initialize the values in the body of the method instead. Because all "real" call sites pass these in (as empty lists), I've added deprecation warnings that we will be removing the default value (and the `| None`) in rbtools 8. Testing Done: Ran unit tests.
f4d05933ad0520da8f5ce34d9a9b67a699905a3d

Checks run (2 succeeded)

flake8 passed.
JSHint passed.