Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove objc._lazyimport, use module __getattr__ and __dir__ instead #295

Closed
ronaldoussoren opened this issue Feb 29, 2020 · 1 comment
Closed
Labels
cleanup enhancement New feature or request

Comments

@ronaldoussoren
Copy link
Owner

This will require dropping Python 3.6 support, and will have to wait for the next major release.

PyObjC lazily loads data in the framework wrappers to reduce import time. This currently uses a "lazyimport" module that replaces the actual module in sys.modules. As of Python 3.7 it is possible to define __getattr__ and __dir__ at module scope instead.

This makes the code easier to understand and makes it easier to add extra code to framework wrappers.

@ronaldoussoren ronaldoussoren added the enhancement New feature or request label Feb 29, 2020
@ronaldoussoren
Copy link
Owner Author

ronaldoussoren commented Apr 5, 2020

Interestingly it might be possible to implement this for python 3.6 as well, the following seems to work:

import os

Module = type(os)

class GetAttrModule (Module):
    def __getattribute__(self, name):
        try:
            return super().__getattribute__(name)
        except AttributeError:
            return self.__getattr__(name)

os.__getattr__ = lambda name: "<<%s>>"%(name,)
print(os.nosuchattribute)

@ronaldoussoren ronaldoussoren added this to the Internals Cleanup milestone Jan 2, 2022
ronaldoussoren added a commit that referenced this issue Jun 8, 2023
This implements a new function for loading a framework and
returning module level "__dir__" and "__getattr__" functions
and transitions the AVFoundation bindings to the new way of
working.

Next step will be to transition all other framework bindings.

ObjCLazyModule will stay around until PyObjC 11.

Issue #295
ronaldoussoren added a commit that referenced this issue Jun 10, 2023
This rewrites the __init__.py of all framework bindings to
switch away from ObjCLazyModule to objc.createFrameworkDirAndGetattr.

A side effect of this is that those init files are now a
lot cleaner than before (e.g. cruft removal).

Also adds a test for validating the bundle identifier of
frameworks, and fixes those identifiers in a couple of bindings.

Closes #295 and closes #561.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cleanup enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant