Skip to content
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

Make Tests Python 3.11 Compatible #34506

Merged
merged 6 commits into from
Apr 19, 2024
Merged

Commits on Apr 18, 2024

  1. fix: Be able to clear the process_cache manually in Python 3.11

    Given code like the following
    
    ```
    class Foo:
        @process_cached
        def bar(self):
            pass
    ```
    
    In Python 3.8 referencing `bar` would not call its `__get__` method.
    
    ```
    x = Foo().bar
    ```
    
    However in Python 3.11, making the same call would call the `__get__`
    method, permanently replacing the underlying `process_cached` object
    with the partial function that references it.
    
    This meant that code to clear the cache would work in Python 3.8 but
    would break in 3.11
    
    ```
    Foo().bar.cache.clear()  # Works in 3.8 but not in 3.11
    ```
    
    In 3.11 this results in the following error:
    ```
    E       AttributeError: 'functools.partial' object has no attribute 'cache'
    ```
    
    To make this compatible in both version, we just add the cache as an
    accessible attribute on the partial we generate for our wrapped
    function.
    feanil committed Apr 18, 2024
    Configuration menu
    Copy the full SHA
    b20ac9c View commit details
    Browse the repository at this point in the history
  2. fix: Provide a sequence to random.sample

    The sample function used to automatically convert sets to sequences but
    that is no longer supported starting in 3.11 so we have to do it
    manually.
    
    Reference: https://docs.python.org/3/library/random.html#random.sample
    feanil committed Apr 18, 2024
    Configuration menu
    Copy the full SHA
    87b9c75 View commit details
    Browse the repository at this point in the history
  3. fix: Create a bad unicode file differently.

    In Python 3.11 CSV files are allowed to have null characters so the test
    data is no longer a valid. We update it to not have a valid unicode
    character to still test this code path correctly.
    
    I'm not concerned about the fact that the files with null will get past
    this test beacause there are other checks on the content of the file
    that catch if it doesn't have enough or the right fields so this should
    be a safe change to make to the tests.
    
    Relevant Change in Python: python/cpython#71767
    feanil committed Apr 18, 2024
    Configuration menu
    Copy the full SHA
    08b3f0b View commit details
    Browse the repository at this point in the history
  4. fix: Fix function mocking.

    The way the patch decorator was being used is not supported in python
    3.11.  Use the patch decorator to auto generate the correct mock and
    make the test a bit more readabale.  The new change is both 3.8 and
    3.11 compatible.
    feanil committed Apr 18, 2024
    Configuration menu
    Copy the full SHA
    884fe8a View commit details
    Browse the repository at this point in the history
  5. fix: Don't use the deprecated location for Hashable

    The Hashable object was moved in python 3.3 and support for the old
    location is dropped in python 3.10 the new location is available in
    python 3.8 so we can just update this and it should work with both
    python 3.8 and 3.11
    
    https://docs.python.org/3.8/library/collections.html
    feanil committed Apr 18, 2024
    Configuration menu
    Copy the full SHA
    6ea63da View commit details
    Browse the repository at this point in the history
  6. fix: Remove deprecated getargspec call.

    This function was removed by python 3.11 so update to the alternate
    call that is the current recommended replacement.
    
    https://docs.python.org/3.11/library/inspect.html#inspect.getfullargspec
    feanil committed Apr 18, 2024
    Configuration menu
    Copy the full SHA
    6fb5963 View commit details
    Browse the repository at this point in the history