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

Fixed Compatiblity Issues with Python 3.9 #18

Merged
merged 4 commits into from
Nov 13, 2024
Merged

Conversation

stegm
Copy link
Owner

@stegm stegm commented Sep 12, 2024

According to #17, the code does not run with python 3.9. I updated tox to include 3.9 and also 3.12. I dropped 3.8 because it never worked and support for python will drop in October.

This PR contains code changes which makes it compatible with 3.9. Most of the changes fix the new typing syntax. In api.py the decorator for re-login has to be moved into a function instead a static method.

@stegm stegm force-pushed the change_supported_python branch 2 times, most recently from f55b3ae to 709ca38 Compare September 12, 2024 19:27
@stegm stegm force-pushed the change_supported_python branch from 709ca38 to cd18e93 Compare September 12, 2024 19:29
@stegm stegm marked this pull request as ready for review September 12, 2024 19:33
Copy link

sourcery-ai bot commented Sep 12, 2024

Reviewer's Guide by Sourcery

This pull request addresses compatibility issues with Python 3.9 and updates the supported Python versions. The main changes involve updating type hints, refactoring a decorator, and modifying the project configuration.

File-Level Changes

Change Details Files
Updated type hints for compatibility with Python 3.9
  • Replaced `list[Any]
dict[Any, Any]withUnion[list[Any], dict[Any, Any]]</li><li>Changed str
Refactored the _relogin decorator
  • Moved the _relogin decorator from a static method to a standalone function
  • Updated the decorator implementation to work with the new location
pykoplenti/api.py
Updated project configuration for new Python versions
  • Added Python 3.9 and 3.12 to the tox environments
  • Updated the list of supported Python versions in setup.cfg
  • Modified the CI workflow to test against Python 3.9, 3.10, 3.11, and 3.12
doc/developer.md
setup.cfg
.github/workflows/ci.yaml

Tips
  • Trigger a new Sourcery review by commenting @sourcery-ai review on the pull request.
  • Continue your discussion with Sourcery by replying directly to review comments.
  • You can change your review settings at any time by accessing your dashboard:
    • Enable or disable the Sourcery-generated pull request summary or reviewer's guide;
    • Change the review language;
  • You can always contact us if you have any questions or feedback.

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 @stegm - I've reviewed your changes and they look great!

Here's what I looked at during the review
  • 🟢 General issues: all looks good
  • 🟢 Security: all looks good
  • 🟡 Testing: 4 issues found
  • 🟢 Complexity: all looks good
  • 🟡 Documentation: 1 issue found

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 to tell me if it was helpful.

tests/test_extendedapiclient.py Show resolved Hide resolved
@@ -30,7 +30,7 @@ def client_response_factory(
) -> Callable[[int, Any], MagicMock]:
"""Provides a factory to add responses to a ClientSession."""

def factory(status: int = 200, json: list[Any] | dict[Any, Any] | None = None):
Copy link

Choose a reason for hiding this comment

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

suggestion (testing): Update type hint in client_response_factory for Python 3.9 compatibility

This change is necessary for Python 3.9 compatibility. Consider adding a test case that specifically checks if the factory works correctly with different types of input (list, dict, and None) to ensure the change doesn't introduce any regressions.

Suggested change
def factory(status: int = 200, json: list[Any] | dict[Any, Any] | None = None):
def factory(
status: int = 200,
json: Union[list[Any], dict[Any, Any], None] = None
) -> MagicMock:

tests/test_extendedapiclient.py Show resolved Hide resolved
@@ -40,7 +40,9 @@
async def test_virtual_process_data(
Copy link

Choose a reason for hiding this comment

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

suggestion (testing): Add test for Python 3.9 specific behavior

Since this PR is about fixing compatibility issues with Python 3.9, it would be beneficial to add a test case that specifically checks for correct behavior under Python 3.9, especially regarding the changes made to type hints and any other Python 3.9 specific modifications.

from typing import Any, Callable, Iterable, Union
from unittest.mock import ANY, MagicMock, call
import sys
import pytest

@pytest.mark.skipif(sys.version_info < (3, 9), reason="requires python3.9 or higher")
async def test_virtual_process_data_python39():
    # Test implementation for Python 3.9 specific behavior

doc/developer.md Show resolved Hide resolved
@stegm stegm force-pushed the change_supported_python branch from 1db7361 to 8176a84 Compare September 14, 2024 19:00
@trsqr
Copy link

trsqr commented Nov 8, 2024

This seems to work for me on a system that only has Python 3.9.

@stegm stegm changed the title Fixed compatiblity issues with python 3.9 Fixed Compatiblity Issues with Python 3.9 Nov 13, 2024
@stegm stegm merged commit 21dcb4e into master Nov 13, 2024
5 checks passed
@stegm stegm deleted the change_supported_python branch November 23, 2024 07:44
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