Pyobjc

Latest version: v11.0

Safety actively analyzes 701298 Python packages for vulnerabilities to keep your Python projects secure.

Scan your dependencies

Page 12 of 18

2.4

-----------

.. note::

Sadly enough this changelog is incomplete.

- Fix crash when unarchiving a Python object.

- Add missing calls to ``[super init]`` in the implementation of
OC_PythonUnicode and OC_PythonString (the ObjC proxies for python's
unicode and str types)

- ``objc.addConvenienceForSelector`` is deprecated, primarily to make
it possible to restructure the pyobjc internals.

- Workaround for bug in pip that resulted in pyobjc-core not being pip
installable. Patch by Marc Abramowitz.

- Creating new formal protocols now uses the new runtime API that was
introduced in OSX 10.7. Because of this it is now possible to create
new formal protocols in 64-bit code (when running on OSX 10.7 or later)

- Codebase should work again when Python using ``--enable-unicode=ucs4``.

- BUG: Avoid crashes in calculating with NSDecimal values in Python 3

- Implement '//' operator for NSDecimal and NSDecimalNumber.

- Implement support for the ``round`` builtin in NSDecimal and
NSDecimalNumber

- There is now limited support for packed struct definitions. This
requires that the struct is wrapped using ``objc.createStructType``.

Struct packing is not described in the encoding string for a
structure, which is why special support is needed.

- objc.registerStructAlias now returns the alias type instead of ``None``

- In Python 3.x there is a new way to explicitly specify which (informal)
protocols a class conforms to::

class MyClass (NSObject, protocols=[Protocol1, Protocol2]):
pass

Python 2.x does not support this syntax, you can still use the
following code there::

class MyClass (NSObject, Protocol1, Protocol2):
pass

Note: The Python 2.x style works up to Python 3.2. In Python 3.3 and later
the Python 2.x style declaration no longer works due to changes in the
language.

- It is also possible to specify the protocols that a class conforms to using
a "__pyobjc_protocols__" attribute in the class body. This has the same
interface as the "protocols" keyword argument in Python 3.x.

This is primarily meant to be used by code that needs to work in Python 2
as well as Python 3.

- Updated Python support. With this release PyObjC supports Python 2.6 and later,
including Python 3.3 (which has a completely new representation for unicode strings)

NOTE: Support for 3.3 is very much work in progress right now, there have
been changes for the new unicode representation, but more changes are required.

Known issues:

* metadata conflict error when explicitly implementing a prototype

* one test failure w.r.t. unichar argument arrays

Furthermore there are two refcounting test failures in both 3.2 and 3.3


- Add ``objc.setObjCPointerIsError`` and ``objc.getObjCPointerIsError``.

By default PyObjC will create a ``PyObjCPointer`` object when it tries
to convert a pointer it doesn't know about to Python. These values are
fairly useless and obvious an indication that an API is wrapped improperly.

With ``objc.setObjCPointerIsError(True)`` you can tell the bridge to
raise an exception instead of creating these values.

- -[OC_PythonNumber compare:] calls super when the other value is
an NSNumber and the Python value can be represented using a basic C
type.

This could slightly affect the results of comparing Python and
Cocoa numbers, and avoids unbounded recursion when comparing
Python numbers with NSDecimalNumbers on OSX 10.7 or later.

- Add implementations for methods from the NSComparisonMethods
informal protocol to OC_PythonNumber

- Add '__cmp__' method when the Objective-C class implements the
'compare:' selector.

- Introduced a way to compile bridgesupport data and lazily load wrappers.

Avoid using "from Cocoa import \*" to get the most benefits from this,
use either "import Cocoa" or "from Cocoa import NSObject".

- ``objc.initFrameworkWrapper`` is now deprecated, switch to the new
compiled metadata code instead.

- ``objc.allocateBuffer`` now returns a bytearray on python >= 2.6,
it used to return a buffer object in Python 2.

- ``objc.FSRef.from_pathname`` actually works instead of always raising
a TypeError.

- ``objc.getAssociatedObject``, ``objc.setAssociatedObject`` and
``objc.removeAssociatedObjects`` are wrappers for the corresponding
functions in the Objective-C runtime API. These functions are only
available when PyObjC was build on a system running OSX 10.6 or later,
and the script is also running on such as system.

The ``policy`` argument for ``objc.setAssociatedObject`` is optional and
defaults to ``objc.OBJC_ASSOCIATION_RETAIN``.

2.3

-----------

- Add some experimental code that slightly reduces the amount of
memory used when loading bridgesupport files.

Further work is needed to investigate what causes the memory
usage to increase as much as it does, sadly enough Instruments
doesn't play nice with ``--with-pymalloc`` and for some reason
'import Foundation' crashes with ``--without-pymalloc``.

- "<struct>" definitions in the bridgesupport files can now have
an alias attribute containing the name of Python type that should
be used to proxy values of this type.

This is used in the Quartz bindings to ensure that ``CGRect``
and ``NSRect`` (from the Foundation framework) map onto the
same Python type.

- Added ``objc.registerStructAlias``, a helper function to add
a type encoding that should map on an already existing struct
type.

- Use this to ensure that ``NSRect`` and ``CGRect`` are the same
(in the Foundation and Quartz bindings).

- This version requires Python 2.6 or later, and also supports
Python 3.1 or later.

- BUGFIX: The generic proxy for Python objects now implements
``-(CFTypeID)_cfTypeID``, which should result in less hard to
understand Objective-C exceptions.

- BUGFIX: The metadata file support now checks if the metadata is
compatible with information gathered from the Objective-C runtime.

This ensures that when a native method signature is incompatible
with the signature in a metadata file the bridge won't garble the
correct information (and that in turn avoids hard crashes).

- PyObjC's support for ``NSCoding`` now also works with plain ``NSArchiver``
instances, not just with ``NSKeyedArchiver``.

- (This item is currently only true for python3, need tests for python 2.x)

NSDictionary now fully implements the dict API, except for the differences
not below:

* ``NSDictionary`` doesn't have the ``__missing__`` hook.

* ``NSDictionary`` always copies keys, which gives slightly different
semantics from Python.

* ``NSDictionary.copy`` always returns an immutable dictionary, use
``NSDictionary.mutableCopy`` to get a mutable dictionary.

* Instances of ``NSDictionary`` cannot be pickled

``NSDictionary`` implements one important feature that native Python
dictionaries don't: full support for Key-Value Observations. Sadly enough
it is not possible to support Key-Value Observation of native Python
dictionaries without patching the interpreter.

- NSSet and NSMutableSet implement the same interface as ``frozenset`` and
``set``, except for the differences listed below:

* ``NSSet.copy`` and ``NSMutableSet.copy`` always return an immutable
object, use the ``mutableCopy`` method to create a mutable copy.

* Instances of ``NSSet`` cannot be pickled

* In-place operators are not implemented, which means that ``aSet |= value``
will assign a new object to ``aSet`` (as if you wrote ``aSet = aSet | value``.

This is needed because the bridge cannot know if if ``aSet`` is mutable,
let alone if ``aSet`` is a value that you are allowed to mutate by API
contracts.

* It is not possible to subclass ``NSSet`` and ``NSMutableSet`` in the same
way as Python's ``set`` and ``frozenset`` classes because the Cocoa
classes are class clusters (which means that all instances of ``NSSet``
are actually instances of, non-necessarily public, subclasses.

* Sadly enough ``set([1,2,3]) == NSSet([1, 2, 3])`` evaluates to False,
even though the values are equivalent. Reversing the order of
the test (``NSSet([1, 2, 3]) == set([1,2,3])``) results in the
expected result.

This is caused by the way equality tests for sets are implemented in
CPython and is not something that can be fixed in PyObjC.

- BUGFIX: accessing methods through ``anObject.pyobjc_instancMethods`` is
now safer, before this release this could cause unlimited recursion
(although I'm not sure if it was possible to trigger this without
other changes in this release).

- The PyObjC egg now includes the header files that should be used to
compile to compile the extensions in the framework wrappers, which makes
it a lot easier to access those headers.

- BUGFIX: The definition for Py_ARG_SIZE_T was incorrect, which causes
problems in 64-bit code.

- Initial port to Python 3.x

C-style 'char' characters and 'char*' strings are
translated to/from byte strings ('str' in Python 2.x,
'bytes' in Python 3.x). There is no automatic translation
from Unicode strings.

Objective-C selector names and encoded type strings are
byte strings as well.

NOTE: Python 3 support is pre-alpha at this time: the code compiles
but does not pass tests yet. The code also needs to be reviewed to
check for python3<->objc integration (dict.keys now returns a view,
NSDictionary.keys still returns a basic iterator, ...)

TODO:

* Implement new style buffer support when depythonifying an array of
C structures.

* Documentation updates

- The Python 3.x port does not support transparent proxies for 'FILE*'
"objects" because the ``file`` type in Python3 is not implemented on
top of the C library stdio.

- The Python 2.x port has been enhanced to accept Unicode strings
in more locations.

- Implement support for PEP-3118, for both Python 2.x and Python 3.x.

This means that proxying arrays of basic C types to ObjC can now
make use of the extended type information provided by the PEP-3118
API.

Furthermore it is possible to use ``memoryview`` objects with
``NSData`` instances, with the limitation that the memoryview *must*
be cleaned up before the currently active autorelease pool is cleared,
or the data instance is resized. That's a result of API restrictions
in Apple's frameworks.

- The PyObjCTest testsuite now supports version-specific tests: for
Python 2.x it will load modules whose name starts with 'test2\_' and for
Python 3.x those starting with 'test3\_'. For both versions it will
load test modules whose name starts with 'test\_' as well.

- Renamed the assertion functions in ``PyObjCTools.TestSupport``, added
``assertFoo`` methods and deprecated the ``failIfFoo`` and ``failUnlessFoo``
methods (similarly to what's happening in the stdlib).

- Added ``objc.propertiesForClass``. This function returns information about
properties for a class from the Objective-C runtime. The information does
not include information about properties in superclasses.

- Added ``objc.object_property``. This is class behaves similarly to
``property``, but integrates better with Objective-C code and APIs like
Key-Value Observation.

- Added ``objc.array_property``. This is similar to ``objc.object_property``,
but models a list-like object and implements the right Objective-C interfaces
for Key-Value Coding/Observations.

- Added ``objc.set_property``. This is similar to
``objc.object_property``, but models a set-like object and implements the
right Objective-C interfaces for Key-Value Coding/Observations.

- Added ``objc.dict_property``. This is similar to
``objc.object_property``, but models a dict-like object and implements the
right Objective-C interfaces for Key-Value Coding/Observations.

- NOTE: The interfaces of ``array_property``, ``set_property`` and ``dict_property``
are minimal w.r.t. options for tweaking their behaviour. That will change in
future versions of PyObjC.

Please let us know which hooks would be useful.

- The documentation is now written using Sphinx.

NOTE: This is an operation in progress, the documentation needs work to be
truly useful.

- The (undocument) module ``PyObjCTools.DistUtilsSupport`` is no longer
present.

- Converting a negative value to an unsigned integer now causes
a deprecation warning, this will be a hard error once I update
all framework wrapper metadata.

2.2

------------------------

- BUGFIX: Ensure PyObjC compiles cleanly with Python 2.6.4.

- BUGFIX: It is now possible to explicitly define ``__getitem__`` (and other
special methods) if your class implements ``objectForKey:``::

class MyObject (NSObject):
def objectForKey_(self, k):
pass

def __getitem__(self, k):
pass

In previous version of PyObjC the implementation of ``__getitem__`` would
silently be replaced by a generic one.

- The default value for the ``__useKVO__`` attribute in class definitions
can now be controlled by ``objc.setUseKVOForSetattr(b)``. The default
is ``True``.

Note: in previous versions the default was ``False``.

Note2: the ``__useKVO__`` attribute is an implementation detail and should
not be used in normal code.

This change fixes an issue where KVO failed to detect some changes when
those changes were done in Python using attribute access syntax.

- Wrappers for ``objc_sync_wait``, ``objc_sync_notify`` and
``objc_sync_notifyAll`` have been removed. These have never been part of
the public API and this should therefore not affect existing code.

- BUGFIX: There was a refcount leak in the code that proxies native code to
Python. This causes refcount leaks in user code when a Python class is
instantiated from native code, when that class has an initializer written
in Python.

Thanks to Dirk Stoop of Made by Sofa for providing the bugreport that helped
fix this issue.

- ``objc.recycleAutoreleasePool`` is now a no-op when a python bundle is loaded
in an Objective-C program and the PyObjC's global release pool gets drained
by an outer release pool. This should not affect user programs.

- BUGFIX: Storing pure python objects in a ``NSKeyedArchiver`` archive didn't
full work for all tuples, especially self-recursive tuples.

The current support for archiving Python objects passes all pickle unittests
in Python 2.7.

- BUGFIX: ``+new`` is supposed to return an already retained object (that is,
the caller owns a reference). Until now PyObjC has assumed that the return
value of ``+new`` is an autoreleased value. The same is true for all class
methods whose name starts with ``new``.

- There is initial support for Objective-C blocks, based on the implementation
description in the `clang repository`__. Blocks are represented in Python
as callable objects. This means you can pass an arbitrary callable when
an Objective-C argument is a block, and that when your method accepts a block
it will get passed a callable object.

There are some limitations on the usage of blocks due to lack of introspection
in the current implementation of blocks. This has two side-effects:

* There must be metadata to describe the signature of blocks in PyObjC's
metadata XML files.

* Block metadata is not retained when a block is stored in an ObjC datastructure,
such as an ``NSArray``, and there are no direct references to the block from
Python.

.. __: https://clang.llvm.org/docs/Block-ABI-Apple.html

- ``objc.inject`` is no longer support. This was code that had no real relation
to the rest of PyObjC and was only working in 32-bit mode with little reason
to expect that it would ever be ported to 64-bit mode.

- Move the testsuite from ``objc.test`` to ``PyObjCTest`` and no longer
install the tests.

The tests are no longer installed because they aren't needed for
day-to-day usage of PyObjC. Furthermore this change will make it possible
to copy all of the pyobjc-core "egg" into an application bundle without
adding unnecessary files to that bundle.

- BUGFIX: Storing pure python objects in a ``NSKeydArchiver`` archive didn't
work 100% reliably for Python floats. I've changed the implementation on
for encoding floats a little and now floats do get rounddtripped properly.

The side effect of this is that archives written by PyObjC 2.2b2 or later
cannot always be read by earlier versions (but PyObjC 2.2b2 can read archives
created with earlier versions).

- BUGFIX: Enable building from source with the Python.org binary distribution.

- BUGFIX: Fix crash when using the animotor proxy feature of CoreAnimation.
That is, the following code now works:

.. sourcecode:: python
:linenos:

app = NSApplication.sharedApplication()
window = NSWindow.alloc().init()
anim = window.animator()
anim.setAlphaValue_(1.0)


- Improve handling of non-methods in objc.Category:

* The docstring of a category is now ignored

* You'll get an explicit error exception when trying to add and ``ivar`` to
a class

* It's now possible to add class attributes in a category:

.. sourcecode:: python
:linenos:

class NSObject (objc.Category(NSObject)):
aClassDefault = [ 1, 2, 3 ]

classmethod
def getDefault(cls):
return cls.aClassDefault



- Fixed support for ``FSRef`` and ``FSSpec`` structures.

* Transparently convert ``Carbon.File.FSRef`` and ``Carbon.File.FSSpec``
instances to C.

* The types ``objc.FSRef`` and ``objc.FSSpec`` are the native
PyObjC representation for ``FSRef`` and ``FSSpec`` structures.

- Added more magic signature heuristics: the delegate selector for
sheets is now automatically recognized, removing the need for
the decorator ``AppHelper.didEndSelector`` (which will stay present
for backward compatibility).

FIXME: Do the same thing for ``objc.accessor``. Both are a frequent
source for errors.

- Added ``PyObjC.TestSupport``. This is an unsupported module containing
useful functionality for testing PyObjC itself.

- Added ``free_result`` attribute to the ``retval`` element in metadata
files. When this attribute has value ``'true'`` the return value of the
C function (or ObjC-method) will be free-ed using the function ``free()``,
otherwise the bridge assumes other code is responsible to free the result.

This is to be used for low-level C API's that return a pointer to a
dynamically allocated array that is to be free-ed by the caller. One example
is the function ``DHCPClientPreferencesCopyApplicationOptions`` in the
SystemConfiguration framework.

- Added ``objc.context``, which is helpful for dealing with "context"
arguments as used by several Cocoa APIs. The context argument must be
a number in Python, while you'd prefer to pass in an arbitrary object
instead. The ``objc.context`` registry allows you to get a context
integer for an arbitrary Python object, and retrieve that later on.

To get the context integer for a Python object:

.. sourcecode:: python

ctx = objc.context.register(myValue)

To unregister the object when you no longer need the context integer:

.. sourcecode:: python

objc.context.unregister(myValue)

To retrieve the Python object given a context integer:

.. sourcecode:: python

myValue = objc.context.get(ctx)


NOTE: This API is particularly handy when using Key-Value Observing, where
the context number should be a unique value to make ensure that KVO usage
by the superclass doesn't get confused with your own usage of KVO.

- PyObjC can now run in 64-bit mode.

NOTE: 64-bit support is beta quality, that is: all unittests pass, but I
haven't tried running real programs yet and hence there might be issues
lurking below the surface.

NOTE: 64-bit support does not yet work on PPC due to a bug in libffi which
prevents catching Objective-C exceptions.

This requires Leopard (OSX 10.5), earlier version of the OS don't have a
64-bit Objective-C runtime at all. This currently also requires a copy of
python that was build with ``MACOSX_DEPLOYMENT_TARGET=10.5``.

Note that class posing (the ``poseAsClass_`` class method) is not supported
in 64-bit mode. It is also not possible to create new protocols in 64-bit
code. Neither are supported by the 64-bit runtime APIs (that is, it is a
restriction in Apple's Objective-C 2.0 runtime).

- There now is a custom proxy class for instances of ``datetime.date`` and
``datetime.datetime``, which takes away the need to manually convert these
instances before using them from Objective-C (such as using an
``NSDateFormatter``)

- Objective-C classes that support the ``NSCopying`` protocol can now be
copied using ``copy.copy`` as well.

..
it would be nice to have the following, but that's not easy to achieve::
- Objective-C classes that support the ``NSCoding`` protocol can now be
copied using ``copy.deepcopy``.

- ``OC_PythonArray`` and ``OC_PythonDictionary`` now explicitly implement
``copyWithZone:`` and ``mutableCopyWithZone:``, copies will now be
Python objects instead of regular ``NSDictionary`` instances.

- Pure Python objects now support the ``NSCopying`` protocol.

- A new decorator: ``objc.namedselector`` for overriding the Objective-C
selector. Usage:

.. sourcecode:: python
:linenos:

class MyObject (NSObject):

objc.namedselector("foo:bar:")
def foobar(self, foo, bar):
pass

- A number of new type signature values were added. These are not present
in the Objective-C runtime, but are used to more precisely describe the
type of some arguments.

The new values are:

* ``_C_UNICHAR``: A "UniChar" value in Objective-C

* ``_C_NSBOOL``: A "BOOL" value in Objective-C

* ``_C_CHAR_AS_INT``: A "char" in Objective-C that is used as a number

* ``_C_CHAR_AS_TEXT``: A "char" in Objective-C that is used as a character

PyObjC will automatically translate these values into the correct Objective-C
type encoding when communicating with the Objective-C runtime, making this
change transparent to anyone but Python users.

NOTE: ``_C_CHR`` is of course still supported, with the same semi-schizofrenic
behaviour as always.

NOTE2: The non-standard metadata extensions we used before to indicate
that a C short is used as a unicode string are no longer supported.

- Output arguments are no longer optional. They must be specified both in
method implementations and method calls. In PyObjC 2.0 they were optional,
but raised a deprecation warning, for backward compatibility with PyObjC 1.x.

The backward compatibility code was removed because it made code more
complicated and actually caused some bugs.

- In PyObjC 1.x you could redefine an Objective-C class, as long as you
redefined it in the same module (such as by reloading a module). That
functionality didn't work in PyObjC 2.0 and is now completely removed
because the functionality isn't supported by the Objective-C 2.0 runtime.

- Adds custom wrappers for some more Python types:

* ``OC_PythonNumber``: wraps python numeric types

This is used instead of ``NSNumber`` because we might loose information
otherwise (such as when using custom subclasses of ``int``).

* ``OC_PythonSet``: wraps a python set and is a subclass of ``NSMutableSet``

- BUGFIX: ``OC_PythonEnumerator`` now actually works.

- BUGFIX: using the ``throw`` syntax one can raise arbitrary objects as
exceptions (not just instances of NSException) in Objective-C. All
instances of NSObject are now converted to Python exceptions, throwing
some other object (such as a C++ exception) will still case a fatal
error due to an uncaught exception.

(SF Bug: 1741095)

- BUGFIX: ``repr(CoreFoundation.kCFAllocatorUseContext)`` now works

(SF Bug: 1827746)

- BUGFIX: The wrappers for CoreFoundation types no longer create a new type
in the Objective-C runtime, that type wasn't used anywhere and was an
unwanted side-effect of how CoreFoundation types are wrapped.

- BUGFIX: The docstring for newly defined methods is no longer hidden
by PyObjC. That is, given this code:

.. sourcecode:: python
:linenos:

class MyObject (NSObject):
def doit(self):
"do something"
return 1 + 2

``MyObject.doit.__doc__`` now evaluates to ``"do something"``, in previous
versions of PyObjC the docstring was ``None``.

- BUGFIX: Fixed calling and implementation methods where one or more
of the arguments are defined as arrays, like this:

.. sourcecode:: objective-c

-(void)fooCallback:(NSRect[4])rects;

There were various issues that caused these to not work correctly in
all earlier versions of PyObjC (which wasn't noticed earlier because
Apple's frameworks don't use this construction).

- BUGFIX: correctly select the native implementation of the compatibility
routines for the ObjC 2.0 runtime API when running on 10.5 (when compiled
for OSX 10.3 or later).

- BUGFIX: fix a number of compatibility routines (ObjC 2.0 runtime API
on OSX 10.4 or earlier).

2.0.1

----------------------------------------

- BUGFIX: ``objc.inject`` works on Leopard (at least on Intel Macs, haven't
tested on PPC).

- BUGFIX: don't crash when printing CF objects that are magic cookies.

- BUGFIX: It is now possible to override ``respondsToSelector:`` in Python.

- Add support for interacting with 'synchronized' blocks in Objective-C.

The function ``object_lock(object)`` is a contextmanager that acquires and
releases the 'synchronized' mutex for an object, and can also be used
manually.

That is (as context manager):

.. sourcecode:: python
:linenos:

from __future__ import with_statement

obj = NSObject.new()

with objc.object_lock(obj):
Perform work while owning the synchronize lock
pass

or (manually):

.. sourcecode:: python
:linenos:

obj = NSObject.new()
mutex = objc.object_lock(obj)
mutex.lock()
try:
Perform work while owning the synchronized lock
pass
finally:
mutex.unlock()

Note that the first version is slightly saver (see the documentation
for with-statements for the details).

2.0

----------------------------

- The basic infrastructure for playing nice in a GC host was added.

This doesn't mean that PyObjC now actually plays nice with the ObjC
garbage collector, some more development and much more testing is
needed for that.

Even so, the end result is about as good as we have without GC,
programs won't make optimal use of GC because that would require
surgery on the Python interpreter itself.

- The metadata returned by the ``__metadata__`` method is slightly changed
to make it more compatible with the XML files.

- Some of the older metadata attributes, such as ``isAlloc`` and
``doesDonateRef`` were dropped. ``isAlloc`` isn't needed for anything but
a number of now hardcoded methods (``+alloc`` and ``+allocWithZone:``),
``doesDonateRef`` is available through the new metadata mechanism.

- Fix a memory leak in the code that creates the python representation for
method lists.

- Speed up framework loading due to three changes:

1. Don't rescan the list of classes unless the framework actually defines
new classes.

2. The metadata loader now implemented in C.

3. CF wrapper types (e.g. CGContextRef) no longer have methods
corresponding to global functions, the speed-hit for calculating
these is too large.

- It is now conveniently possible to create instance variables with
a specific type (e.g. without manually making up a encoded type
string):

.. sourcecode:: python
:linenos:

class MyObject (NSObject):
bounds = objc.ivar.NSRect()
done = objc.ivar.bool()

- Objective-C metaclasses are modelled as Python metaclasses. This brings
a major improvement: class methods "just work"(TM):

.. sourcecode:: python
:linenos:

o = NSObject.alloc().init()
o.description()

NSObject.description()

In earlier versions of PyObjC the second call would fail because
``NSObject.description`` referred to an unbound instance-method instead of
to the class method.

This change should require little or change to existing code. There's only
two types of code where the new behaviour is incompatible:

1) Code that introspects the class dictionary to see what methods are
available. These will no longer see class methods, but will have to look
at the metaclass as well. This affects ``pydoc(1)`` as well.

2) Code that uses unbound instance methods will no pick up class methods
in some occasions. Use ``MyClass.instanceMethodForSelector_`` instead of
unbound methods, or alternatively access instance methods through
``MyClass.pyobjc_instanceMethods``.

3) Due to a limitation in the implementation of python's ``super`` class [f1]_
it is not possible to use the super machinery to resolve class methods.

However, ``from Foundation import *`` will replace the builtin ``super``
by a subclass that does work correctly for PyObjC programs, therefore
this doesn't affect most PyObjC-using programs.


.. [f1] It is not possible to override the way ``super`` looks for the "next"
method to call. The class ``objc.super`` is a subclass of the builtin
superclass with a ``__getattr__`` implementation that does the right thing
for supercalls for Objective-C class methods.

- It is now easily possible to tell PyObjC that a Python type should be
treated like a builtin sequence type:

.. sourcecode:: python
:linenos:

import UserList, objc

class MyClass (UserList.UserList):
pass

objc.registerListType(MyClass)

- And likewise for mapping types using ``objc.registerMappingType``.

- ``objc.enableThreading()`` is gone. It was introduced in ancient times to
enable threading in the Python runtime but has been a no-op for ages because
the PyObjC enables threading by default now.

- The unittests can now use the leaks(1) command to check for memory leaks. This
slows testing down significantly and is therefore off by default. Enable by
setting ``PYOBJC_WITH_LEAKS`` to a value in the shell environment before running
the tests:

.. sourcecode:: sh

$ PYOBJC_WITH_LEAKS=1 python setup.py test

NOTE: the actual value is ignored, as long as there is a value.

- (BUGFIX): PyObjC was leaking memory when doing scans of the Objective-C method tables

- (BUGFIX): The code below now raises an error, as it should have done in previous versions but never
did:

.. sourcecode:: python
:linenos:

class MyObject (object):
def updateDescription(self):
self.description = 42


- PyObjC has been split into several smaller packages: ``pyobjc-core`` contains
the core bridge and frameworks are wrapped as separate setuptools packages.

- Objective-C objects now have an implicit attribute named ``_`` which can
be used a shortcut for Key-Value-Coding.

The code fragment below:

.. sourcecode:: python
:linenos:

o = <Some Objective-C Object>
print o._.myKey
o._.myKey = 44

is equivalent to:

.. sourcecode:: python
:linenos:

print o.valueForKey_('myKey')
o.setValue_forKey_(44, 'myKey')

The former is much nicer to use.

- Struct wrappers now have a ``copy`` method. This method tries to do the right
thing when subfields are other struct wrappers (that is, deep-copy them).

- The metadata system has been revamped and mostly removes the need to write
C-code when wrapping frameworks (that includes most of the AppKit and
Foundation wrappers as well). The metadata is loaded at runtime from
an XML file, whose format is shared between PyObjC and RubyCocoa.

``objc.initFrameworkWrapper`` can be used to load a framework using
these XML metadata files.

Note: because we now use an XML metadata file the scripts in
``Scripts/CodeGenerators`` have been removed: they are no longer needed. Have
a look at the project ``pyobjc-metadata`` if you want to generate your own
metadata.

Note2: the metadata format is shared with RubyCocoa, although there are
currently some slight differences (that is, the PyObjC metadata is slightly
richer).

- PyObjC now has builtin support for CoreFoundation-based types, which is
used by the new metadata file support. Note that doesn't mean we support
all of CoreFoundation and other CF-based frameworks, just that the machinery
that's needed for that is present and working.

This is a backward incompatible change: CF-based types will now be proxied
using PyObjC-owned types instead of the ones in MacPython. However, PyObjC
will still convert MacPython CF-wrappers to the right native type.

Another backward compatible change: ``registerCFSignature`` has a different
signature:

.. sourcecode:: python

registerCFSignature(name, encoding, typeId [, tollfreeName]) -> type

This is needed to capture all information about CF types.

- This version introduces generic support for callback functions. The metadata
mentioned before contains information about the signature for callback
functions, the decorator ``callbackFor`` converts a plain function to
one that can be used as a callback:

.. sourcecode:: python
:linenos:

objc.callbackFor(NSArray.sortedArrayUsingFunction_andContext_)
def compare(left, right, context):
if left.key < right.key:
return NSOrderedAscending
elif left.key > right.key:
return NSOrderedDescending
else:
return NSOrderedSame

The ``makeCallbackFor`` callback should be used for callbacks where the
callable is stored by the called function and is optional otherwise (such
as the example above).

- The decorator ``selectorFor`` can be used to ensure that a method has the
right signature to be used as the callback method for a specific method.

Usage:

.. sourcecode:: python

objc.selectorFor(NSApplication.beginSheet_modalForWindow_modalDelegate_didEndSelector_contextInfo_)
def sheetDidEnd_returnCode_contextInfo_(self, sheet, returnCode, info):
pass

- PyObjC compiled on Leopard uses the Objective-C 2.0 runtime.

The compiler on 10.5 still gives warning about usage of deprecated APIs unless
compiling for 10.5 or later because of a compatibility layer.

- GNUstep support has been removed because this has never worked properly,
nobody seems interested in fixing that and the internal APIs of PyObjC have
changed greatly.

- Output arguments are treated slightly different. In previous versions you
were not allowed to pass values for output arguments.

This is now deprecated behaviour, you should choose to supply values for all
arguments including output arguments (mixing these two styles is not
allowed, if you have two output argument you must either supply a value for
both of them or neither).

There are only two acceptable values for output argument:

* ``None``: pass a non-NULL pointer to the objc function/method

* ``objc.NULL``: pass a NULL pointer to the objc method.

The already existing behaviour is the same as passing in ``None`` for all
output arguments.

This is most useful for suppressing an ``NSError`` value for methods that
have an ``NSError**`` argument (when you don't want to look at that value),
because generating that object might be expensive.

- ``objc.setSignature`` is deprecated, use the new metadata machinery instead.

- Opaque types (such as NSZonePointer) are now mutable, which is mostly present
to allow framework wrappers to provide a nice OO interface to those types
instead of forcing users to use the procedural API.

None of the current framework wrappers use this feature.

- Several new methods were added to improve integration with a future version
of MacPython: opaque pointer types and ``NSObject`` now have a method
named ``__cobject__`` that returns a ``PyCObject`` which represents the
proxied value. Furthermore both opaque pointer types and subclasses of
``NSObject`` are now callable and will create the proper proxy object when
passed a ``PyCObject``. Note however than the caller is responsible to ensure
that the ``PyCObject`` value represents a value of the right type.

- Archiving pure python objects using ``NSArchiver`` was already unsupported,
we now explicitly raise an exception when users try to do this anyway. It
is supported to archive and retrieve simple values: instances of ``int``,
``long``, ``float``, ``str`` and ``unicode``.

- A ``__del__`` or ``dealloc`` method can revive objects, which isn't really
supported by Objective-C. We'll now warn about this, hopefully before the
program crashes. The warning is ``objc.RevivedObjectiveCObjectWarning``.

- Some functions and methods return an instance of ``objc.varlist``. These
objects behave a little like tuples, but don't have a defined length, you
are responsible to not peak beyond the end of the actual array.

The best way to deal with these objects is to convert them to real tuples
as soon as possbible (using the ``as_tuple`` method). The number of elements
in that tuple should be known to you and depends on the API.

These objects are used in places where objects return an array but the
size of that array cannot be described using the bridge metadata. These
are mostly arrays whose size depends on the state of an object, or whose
size is a function of one or more arguments of the method.

- There now is a public API for adding new "convenience methods", that is
methods that emulate standard Python methods using Objective-C methods.

There are two functions for adding new convenience methods:

* ``addConvenienceForSelector`` adds a list of methods to a class when that
class has the specified selector:

.. sourcecode:: python

addConvenienceForSelector('hash', [
('__hash__', lambda self: self.hash()),
])

* ``addConvenienceForClass`` adds a list of methods to the class with the
specified name:

.. sourcecode:: python

addConvenienceForSelector('NSObject', [
('dummy', lambda self: 42 ),
])

In both cases the addition is done lazily, the class that will be changed
need not be loaded at the time of the call.

- Fix a long-standing race condition where one could end up with a reference
to an already deallocated Objective-C object when the last ObjC reference
goes away on one thread and is just "recreated" on a second thread.

- The 'name' and 'reason' of an Objective-C exception are now represented as
Unicode objects in the Python representation of the exception, instead of
as a UTF-8 encoded string.

The standard Python exception message is still a UTF-8 encoded string,
that's needed to ensure that we can always print the value of the exception
message (such as in tracebacks).

1.4.1

--------------------

- PyObjC now uses setuptools. Setuptools support is fairly minimal at the
moment, we expect to move more of the build infrastructure to setuptools and
to split PyObjC into smaller eggs.

- Fix an issue that made is possible to create weakref's to subclasses of
subclasses of Objective-C classes. This was unintentional behaviour, the
weakref is to the proxy (see the news for 1.0b1 for more details).

- Add RoundTransparentWindow and DragItemAround examples in ``Examples/AppKit``.

Both are ports of Objective-C examples at ADC and were provided by
ytrewq1.

- Fix issue where programs would crash with an badly aligned C-stack on
some problems. This issue only affected Intel systems.

- Remove ``OC_PythonObject.pythonifyStructTable``. This method of wrapping
structs was untested and not used in the core distribution. Use
``objc.createStructType`` instead.

- Binaries build on 10.4 also work on 10.3. This means it is no longer
necessary to build PyObjC on the lowest version of the OS that you want
to run your binaries on. Doing this with python is somewhat of a black
art, please test your applications on the lowest version of the OS that
you want to support to make sure that this actually works.

Page 12 of 18

© 2025 Safety CLI Cybersecurity Inc. All Rights Reserved.