GrahamDumpleton / wrapt

A Python module for decorators, wrappers and monkey patching.
BSD 2-Clause "Simplified" License
2.04k stars 230 forks source link

Port wrapt to heap types and stable ABI #187

Open tiran opened 2 years ago

tiran commented 2 years ago

Port wrapt to use heap types and stable ABI. Python's stable ABI does not support static types and makes type struct opaque.

wrapt uses some features that are not supported by limited API in Python 3.8 and earlier. I modified the code to use unstable API for 3.6 to 3.8 and limited API + abi3 for 3.9+.

GrahamDumpleton commented 2 years ago

I would need to make a last release with Python 2.7 support first. I keep forgetting to release 1.13 with all the wheel stuff. I should do that tomorrow I guess. :-)

tiran commented 2 years ago

I'm unable to run any tests locally:

$ tox -e py39-install-extensions
...
Traceback (most recent call last):
  File "/usr/lib/python3.9/site-packages/setuptools/config.py", line 33, in __getattr__
    return next(
  File "/usr/lib/python3.9/site-packages/setuptools/config.py", line 34, in <genexpr>
    ast.literal_eval(statement.value)
  File "/usr/lib64/python3.9/ast.py", line 105, in literal_eval
    return _convert(node_or_string)
  File "/usr/lib64/python3.9/ast.py", line 104, in _convert
    return _convert_signed_num(node)
  File "/usr/lib64/python3.9/ast.py", line 78, in _convert_signed_num
    return _convert_num(node)
  File "/usr/lib64/python3.9/ast.py", line 69, in _convert_num
    _raise_malformed_node(node)
  File "/usr/lib64/python3.9/ast.py", line 66, in _raise_malformed_node
    raise ValueError(f'malformed node or string: {node!r}')
ValueError: malformed node or string: <ast.Call object at 0x7fc5ffbdd970>

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/usr/lib/python3.9/site-packages/setuptools/config.py", line 387, in _parse_attr
    return getattr(StaticModule(module_name), attr_name)
  File "/usr/lib/python3.9/site-packages/setuptools/config.py", line 41, in __getattr__
    raise AttributeError(
AttributeError: wrapt has no attribute __version__

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/heimes/dev/py/wrapt/setup.py", line 33, in <module>
    setuptools.setup(
  File "/usr/lib/python3.9/site-packages/setuptools/__init__.py", line 153, in setup
    return distutils.core.setup(**attrs)
  File "/usr/lib64/python3.9/distutils/core.py", line 121, in setup
    dist.parse_config_files()
  File "/usr/lib/python3.9/site-packages/setuptools/dist.py", line 680, in parse_config_files
    parse_configuration(self, self.command_options,
  File "/usr/lib/python3.9/site-packages/setuptools/config.py", line 157, in parse_configuration
    meta.parse()
  File "/usr/lib/python3.9/site-packages/setuptools/config.py", line 463, in parse
    section_parser_method(section_options)
  File "/usr/lib/python3.9/site-packages/setuptools/config.py", line 436, in parse_section
    self[name] = value
  File "/usr/lib/python3.9/site-packages/setuptools/config.py", line 220, in __setitem__
    value = parser(value)
  File "/usr/lib/python3.9/site-packages/setuptools/config.py", line 552, in _parse_version
    version = self._parse_attr(value, self.package_dir)
  File "/usr/lib/python3.9/site-packages/setuptools/config.py", line 390, in _parse_attr
    module = importlib.import_module(module_name)
  File "/usr/lib64/python3.9/importlib/__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1030, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
  File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 680, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 850, in exec_module
  File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed
  File "/home/heimes/dev/py/wrapt/src/wrapt/__init__.py", line 13, in <module>
    from .importer import (register_post_import_hook, when_imported,
  File "/home/heimes/dev/py/wrapt/src/wrapt/importer.py", line 48, in <module>
    def register_post_import_hook(hook, name):
AttributeError: 'function' object has no attribute 'keys'
GrahamDumpleton commented 2 years ago

Not sure whether was same error, but tox on macOS has been broken for me for a while, but under Linux with GitHub actions has been working fine. So I wasn't sure if was some local issue in my setup.

GrahamDumpleton commented 2 years ago

Actually, was also working find under macOS and Windows under GitHub actions, thus why figured my system was broken.

GrahamDumpleton commented 2 years ago

My memory is obviously bad, tox runs fine for me locally so I obviously fixed the issue. This is before your changes though. Not tried those and they fail for all C extensions tests under GitHub actions as well.

tiran commented 2 years ago

@GrahamDumpleton I figured out all the segfaults and got most tests passing. There are two failing tests for Python 3.10's annotation overrides left.

GrahamDumpleton commented 2 years ago

Getting close. :-)

tiran commented 2 years ago

I filed https://bugs.python.org/issue45319 for the __annotations__ issue with Python 3.10