Skip to content

Conversation

@ulgens
Copy link
Contributor

@ulgens ulgens commented Nov 10, 2025

Description

Update pyupgrade config for Python 3.9. It seems this wasn't handled during 3.8 removal.

@ulgens ulgens mentioned this pull request Nov 10, 2025
# NOTE: The guard for Python 3.9 is because types.GenericAlias is only added in Python 3.9. This is not a problem
# as the syntax is added in the same version in the first place.
if (3, 9) <= sys.version_info < (3, 11) and isinstance(annotation, types.GenericAlias):
if sys.version_info < (3, 11) and isinstance(annotation, types.GenericAlias):
Copy link
Member

Choose a reason for hiding this comment

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

should be 3, 10

Copy link
Contributor Author

@ulgens ulgens Nov 10, 2025

Choose a reason for hiding this comment

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

@auvipy Can you please give more details? This upper version limit is not something I touch with this PR and I don't know much about why it's implemented.

Copy link
Member

Choose a reason for hiding this comment

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

It appears only this was removed:

# NOTE: The guard for Python 3.9 is because types.GenericAlias is only added in Python 3.9. This is not a problem
    #       as the syntax is added in the same version in the first place.
    if (3, 9) <=

Which matches the scope of the PR. Anything we’re missing @auvipy ?

Copy link
Member

Choose a reason for hiding this comment

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

I am considering whether we need to revert this specific change @ulgens .

Original code:

def annotation_is_class(annotation: typing.Any) -> bool:
    """Test if a given annotation is a class that can be used in isinstance()/issubclass()."""
    # isclass() returns True for generic type hints (e.g. `list[str]`) until Python 3.10.
    # NOTE: The guard for Python 3.9 is because types.GenericAlias is only added in Python 3.9. This is not a problem
    #       as the syntax is added in the same version in the first place.
    if (3, 9) <= sys.version_info < (3, 11) and isinstance(annotation, types.GenericAlias):

This is mostly a safeguard, a functionality, that we might actually want to keep for a few more years until Python 3.9 is really out of the game, or, if we officially drop existing support for edge cases, which I prefer not to, at this moment.

Copy link
Contributor Author

@ulgens ulgens Nov 14, 2025

Choose a reason for hiding this comment

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

@Nusnus The change doesn't affect the use of 3.9, it's for anything earlier than 3.9. Because 3.9 is the earliest supported version, (3, 9) <= sys.version _info will always be true - it doesn't need to be checked.

@codecov
Copy link

codecov bot commented Nov 10, 2025

Codecov Report

❌ Patch coverage is 65.78947% with 13 lines in your changes missing coverage. Please review.
✅ Project coverage is 78.68%. Comparing base (b446910) to head (06ab87f).

Files with missing lines Patch % Lines
celery/contrib/pytest.py 0.00% 2 Missing ⚠️
celery/contrib/testing/manager.py 0.00% 2 Missing ⚠️
celery/fixups/django.py 0.00% 2 Missing ⚠️
celery/utils/collections.py 0.00% 2 Missing ⚠️
celery/utils/log.py 0.00% 2 Missing ⚠️
celery/utils/text.py 0.00% 2 Missing ⚠️
celery/utils/time.py 0.00% 1 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main    #9987   +/-   ##
=======================================
  Coverage   78.68%   78.68%           
=======================================
  Files         153      153           
  Lines       19330    19337    +7     
  Branches     2221     2220    -1     
=======================================
+ Hits        15209    15215    +6     
  Misses       3824     3824           
- Partials      297      298    +1     
Flag Coverage Δ
unittests 78.66% <65.78%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@Nusnus Nusnus added this to the 5.7.0 milestone Nov 10, 2025
Copy link
Member

@Nusnus Nusnus left a comment

Choose a reason for hiding this comment

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

Thank you for this PR!

LGTM so far, though we’ll need to wait before deprecating 3.9 in main.

@ulgens
Copy link
Contributor Author

ulgens commented Nov 10, 2025

@Nusnus Thank you. To clarify, this PR doesn't serve to the deprecation of 3.9 - it cleans residues from <3.9 support and can be merged safely in the current release.

@Nusnus
Copy link
Member

Nusnus commented Nov 10, 2025

@Nusnus Thank you. To clarify, this PR doesn't serve to the deprecation of 3.9 - it cleans residues from <3.9 support and can be merged safely in the current release.

Thank you for the correction. I was reviewing #9988 just before so I had my mind on the deprecation hehe

ulgens added a commit to myperfectstay/celery that referenced this pull request Nov 10, 2025
These were added in
* celery@f1ddd58
* celery@c4e4bab

but they are not helpful. Decided to clean in celery#9987 (comment)
@Nusnus Nusnus requested a review from auvipy November 10, 2025 19:40
Nusnus pushed a commit that referenced this pull request Nov 14, 2025
These were added in
* f1ddd58
* c4e4bab

but they are not helpful. Decided to clean in #9987 (comment)
@ulgens ulgens force-pushed the pyupgrade-python-3.9 branch from 9fe86c9 to afb57e4 Compare November 14, 2025 08:55
@ulgens ulgens force-pushed the pyupgrade-python-3.9 branch from afb57e4 to 06ab87f Compare November 23, 2025 15:34
@ulgens
Copy link
Contributor Author

ulgens commented Nov 23, 2025

@Nusnus Is there any chance to handle this in 5.6.0?

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.

3 participants