aws / aws-cli

Universal Command Line Interface for Amazon Web Services
Other
15.09k stars 4.01k forks source link

Remove six from awscli codebase #8754

Closed nateprewitt closed 1 week ago

nateprewitt commented 1 week ago

This PR removes usage of six in the CLI v1 codebase and minimizes its presence to one import from Botocore. This is left in place for backwards compatibility but is considered deprecated and may be removed in a future version. Downstream distributors may choose to patch out this single import to remove the requirement on keeping six in their ecosystem.

The primary changes here are in three classes:

  1. six.*_type(s), six maintains references to things like bytes, str, basestr, unicode depending on the Python version being used. We're removing this for the direct call to either str for six.text_type or bytes for six.binary_type. This also applies to six.integer_types and six.string_types which are used for type checking.

    >>> import six
    >>> six.text_type
    <class 'str'>
    >>> six.binary_type
    <class 'bytes'>
    >>> six.string_types
    (<class 'str'>,)
    >>> six.integer_types
    (<class 'int'>,)
  2. six.moves.*, these changes are placeholders that map between changed references to the same class. This was to account for modules that got renamed in Python 3. These are no longer needed so they've been moved to their Python 3 equivalent, you can find the full mapping table here.

  3. six.b() six.u(), six.BytesIO(), six.StringIO(), these are used for bringing StringIO/BytesIO back to Python 2 and dealing with the differences of bytes/unicode between the two major versions. StringIO and BytesIO are already present in the standard library io module, so we no longer need six for these. For six.b and six.u, these are just syntax sugar around value.encode('latin-1') and a literal no-op for six.u in Python 3. There's some discussion to be had on whether this should really be value.encode('utf-8') where we're using six.b but I've left it exactly as it was with six to make sure we're not breaking anything.

If you have more questions, you can read the full six docs here.

nateprewitt commented 1 week ago

Good call out, it looks like there's actually a bunch of usage in the test directory. The grep expression I was using missed a number of these, I've updated it and will get those pushed up.

Nevermind, I see what was happened. This is only one of the two commits, they were split up to ensure tests still pass with the changes and not removing six from the test infrastructure. Should be good now.