Skip to content

Conversation

@matthewfeickert
Copy link
Member

@matthewfeickert matthewfeickert commented Oct 16, 2025

Description

Pulling in parts of PR #2566

  • Support Python 3.9+, dropping support for Python 3.8.
  • Simplify code by removing components that existed to support pre Python 3.9
    features or solutions.
  • Use improved typing features from Python 3.9.
  • Remove importlib_resources conditional dependency for Python < 3.9.
  • Remove Python 3.8 trove classifier.
  • Use Python 3.10 for the mypy minimum python check, due to Numpy typing being improved in 3.10+.

Checklist Before Requesting Reviewer

  • Tests are passing
  • "WIP" removed from the title of the pull request
  • Selected an Assignee for the PR to be responsible for the log summary

Before Merging

For the PR Assignees:

  • Summarize commit messages into a comprehensive review of the PR
* Support Python 3.9+, dropping support for Python 3.8.
* Simplify code by removing components that existed to support pre Python 3.9
  features or solutions.
* Use improved typing features from Python 3.9.
* Remove importlib_resources conditional dependency for Python < 3.9.
* Remove Python 3.8 trove classifier.
* Use Python 3.10 for the mypy minimum python check, due to Numpy typing being
  improved in 3.10+.

Co-authored-by: Giordon Stark <[email protected]>

@matthewfeickert matthewfeickert self-assigned this Oct 16, 2025
@matthewfeickert matthewfeickert added docs Documentation related build Changes that affect the build system or external dependencies type checking Related to types and type checking python Pull requests that update Python code labels Oct 16, 2025
@github-project-automation github-project-automation bot moved this to In progress in pyhf v0.8.0 Oct 16, 2025
@matthewfeickert matthewfeickert marked this pull request as ready for review October 16, 2025 09:25
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR drops support for Python 3.8 and adopts Python 3.9+ features, simplifying the codebase by removing compatibility shims and leveraging improved typing capabilities.

Key changes:

  • Removed conditional imports for importlib.resources (now always available in Python 3.9+)
  • Updated type hints to use built-in generic types (list, tuple, set) and moved abstract types (Sequence, Mapping) from typing to collections.abc
  • Simplified archive validation logic in contrib/utils.py to use direct is_tarfile/is_zipfile checks instead of try-except pattern

Reviewed Changes

Copilot reviewed 18 out of 18 changed files in this pull request and generated no comments.

Show a summary per file
File Description
tests/contrib/test_viz.py Removed Python 3.8 version check xfail decorator
src/pyhf/utils.py Removed conditional import for importlib_resources
src/pyhf/typing.py Updated to use built-in generics and collections.abc imports
src/pyhf/tensor/numpy_backend.py Added type ignore comment and cast for improved type checking
src/pyhf/schema/variables.py Removed conditional import for importlib_resources
src/pyhf/schema/validator.py Moved Mapping import to collections.abc
src/pyhf/schema/loader.py Removed conditional import for importlib_resources
src/pyhf/readxml.py Updated type hints to use built-in generics and collections.abc
src/pyhf/pdf.py Changed List[bool] return type to list[bool]
src/pyhf/parameters/paramsets.py Changed List[bool] return type to list[bool]
src/pyhf/modifiers/staterror.py Changed List[bool] parameter type to list[bool]
src/pyhf/mixins.py Moved Sequence import to collections.abc
src/pyhf/contrib/utils.py Refactored archive validation from try-except to if-elif-else structure
pyproject.toml Updated minimum Python version to 3.9 and removed 3.8 classifier
.pre-commit-config.yaml Updated mypy checks from Python 3.8 to 3.10
.github/workflows/release_tests.yml Removed Python 3.8 from test matrix
.github/workflows/lower-bound-requirements.yml Updated minimum Python version from 3.8 to 3.9
.github/workflows/ci.yml Removed Python 3.8 from CI test matrix

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

.. versionadded:: 0.7.0
"""
return tensor_in.transpose()
return cast(ArrayLike, tensor_in.transpose())
Copy link
Member Author

Choose a reason for hiding this comment

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

@kratsg this PR is mostly just a cherry-pick from your first commit in PR #2566, but to get Python 3.10 typing with mypy to pass I had to cast the output of transpose to ArrayLike.

I'm not sure if this makes sense or not, so I think you'll need to weigh in here.

@codecov
Copy link

codecov bot commented Oct 16, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98.23%. Comparing base (2af4dea) to head (595ca57).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2625      +/-   ##
==========================================
- Coverage   98.23%   98.23%   -0.01%     
==========================================
  Files          65       65              
  Lines        4198     4190       -8     
  Branches      592      452     -140     
==========================================
- Hits         4124     4116       -8     
  Misses         45       45              
  Partials       29       29              
Flag Coverage Δ
contrib 98.11% <100.00%> (+0.13%) ⬆️
doctest 98.23% <100.00%> (+0.13%) ⬆️
unittests-3.10 96.42% <86.36%> (+0.13%) ⬆️
unittests-3.11 96.42% <86.36%> (+0.13%) ⬆️
unittests-3.12 96.42% <86.36%> (+0.13%) ⬆️
unittests-3.13 96.42% <86.36%> (+0.13%) ⬆️
unittests-3.8 ?
unittests-3.9 96.46% <90.90%> (+0.13%) ⬆️

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.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@matthewfeickert matthewfeickert force-pushed the build/drop-python-3-8-support branch from 7c7aa31 to 6b95ab7 Compare October 22, 2025 18:43
kratsg and others added 4 commits October 27, 2025 16:47
Sonnet 4's summary:

> The mypy error occurred because the transpose() method on line 659 was
> returning a value that mypy inferred as Any, while the function signature
> declared it should return ArrayLike. Mypy's no-any-return rule flags when
> you return an Any value from a function with a specific return type annotation.
@matthewfeickert matthewfeickert force-pushed the build/drop-python-3-8-support branch from 6b95ab7 to 595ca57 Compare October 27, 2025 22:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

build Changes that affect the build system or external dependencies docs Documentation related python Pull requests that update Python code type checking Related to types and type checking

Projects

Status: In progress

Development

Successfully merging this pull request may close these issues.

2 participants