You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Python 3.14 introduces deferred evaluation of annotations (PEP 649 and PEP 749).
Code that relies on manipulating the __annotations__ attribute directly needs to, instead, make use of annotationlib and the get_annotations() function called with the format=Format.FORWARDREF argument.
In this PR we'll use the typeextensions library which provides a backward-compatible implementation for versions of Python <3.14.
Sorry about the delay. We have chatted about some of this but just to get some notes written down:
I found that running the unit tests with python -m unittest fails after this change, with:
======================================================================
ERROR: test_code_generation (test.test_descriptors.TestDescriptors.test_code_generation)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/home/mike/repos/facedancer/test/test_descriptors.py", line 102, in test_code_generation
new_device = Device()
^^^^^^^^
File "<string>", line 20, in __init__
File "/home/mike/repos/facedancer/facedancer/device.py", line 164, in __post_init__
for configuration in instantiate_subordinates(self, USBConfiguration):
File "/home/mike/repos/facedancer/facedancer/magic.py", line 129, in instantiate_subordinates
yield member(object)
^^^^^^^^^^^^^^
File "/home/mike/repos/facedancer/facedancer/magic.py", line 64, in __call__
return self._target_type(parent=parent)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "<string>", line 10, in __init__
File "/home/mike/repos/facedancer/facedancer/configuration.py", line 111, in __post_init__
for interface in instantiate_subordinates(self, USBInterface):
File "/home/mike/repos/facedancer/facedancer/magic.py", line 129, in instantiate_subordinates
yield member(object)
^^^^^^^^^^^^^^
File "/home/mike/repos/facedancer/facedancer/magic.py", line 64, in __call__
return self._target_type(parent=parent)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "<string>", line 14, in __init__
File "/home/mike/repos/facedancer/facedancer/interface.py", line 88, in __post_init__
for descriptor in instantiate_subordinates(self, USBDescriptor):
File "/home/mike/repos/facedancer/facedancer/magic.py", line 129, in instantiate_subordinates
yield member(object)
^^^^^^^^^^^^^^
File "/home/mike/repos/facedancer/facedancer/magic.py", line 64, in __call__
return self._target_type(parent=parent)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: Device.Configuration_1.Interface_0.Descriptor_0x24_A.__init__() missing 1 required keyword-only argument: 'raw'
I think that this change isn't actually keeping the same behaviour as before. Previously, it was adding to the __annotations__ element in classdict passed to the new class, but the new change is only accessing the base-class annotations and not updating anything in the child class.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Python 3.14 introduces deferred evaluation of annotations (PEP 649 and PEP 749).
Code that relies on manipulating the
__annotations__attribute directly needs to, instead, make use ofannotationliband theget_annotations()function called with theformat=Format.FORWARDREFargument.In this PR we'll use the
typeextensionslibrary which provides a backward-compatible implementation for versions of Python<3.14.More information: https://docs.python.org/3/whatsnew/3.14.html#whatsnew314-porting-annotations
--
Closes #172