Skip to content

fix: pass type(self) to get_type_hints for Python 3.14 compatibility - #15

Merged
codeskyblue merged 4 commits into
masterfrom
copilot/fix-typeerror-statusinfo
Jul 31, 2026
Merged

codeskyblue merged 4 commits into
masterfrom
copilot/fix-typeerror-statusinfo

Conversation

Copilot AI commented Jul 30, 2026

Copy link
Copy Markdown
Contributor

In Python 3.14, __annotations__ became a data descriptor on type, so typing.get_type_hints(instance) raises TypeError: '<ClassName> does not have annotations' instead of falling back to the class. This broke instantiation of all _Base subclasses (StatusInfo, AppInfo, DeviceInfo, BatteryInfo, etc.).

Change

wdapy/_types.py_Base.__init__: pass type(self) instead of self to typing.get_type_hints.

# Before (breaks Python 3.14)
for k, _ in typing.get_type_hints(self).items():

# After (compatible Python 3.8–3.14)
for k, _ in typing.get_type_hints(type(self)).items():

Copilot AI changed the title [WIP] Fix TypeError when instantiating _Base subclasses in Python 3.14 fix: pass type(self) to get_type_hints for Python 3.14 compatibility Jul 30, 2026
Copilot AI requested a review from codeskyblue July 30, 2026 11:21
@codeskyblue
codeskyblue marked this pull request as ready for review July 31, 2026 02:25
Copilot AI review requested due to automatic review settings July 31, 2026 02:25
@codeskyblue
codeskyblue merged commit 1705cf6 into master Jul 31, 2026
1 check passed
@codeskyblue
codeskyblue deleted the copilot/fix-typeerror-statusinfo branch July 31, 2026 02:25

Copilot AI left a comment

Copy link
Copy Markdown

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 restores compatibility with Python 3.14 by updating _Base.__init__ to retrieve type hints from the class (type(self)) rather than the instance, avoiding a TypeError introduced by Python 3.14’s annotation handling changes. It also refreshes the PyPI publish workflow’s Python setup step.

Changes:

  • Fix _Base.__init__ to call typing.get_type_hints(type(self)), preventing Python 3.14 instantiation failures for _Base subclasses.
  • Update GitHub Actions setup-python from v1 to v5 and adjust the workflow’s Python version.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
wdapy/_types.py Uses class-based type-hint lookup to keep _Base subclass initialization working on Python 3.14.
.github/workflows/publish_to_pypi.yml Updates Python setup action version and the configured runtime version for the workflow.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +12 to 15
uses: actions/setup-python@v5
with:
python-version: 3.9
python-version: '3.10'
cache: 'pip'
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.

Python 3.14 下实例化 _Base 子类报错 TypeError: '<StatusInfo > does not have annotations'

3 participants