The Python <-> Objective-C Bridge with bindings for macOS frameworks
Bot releases are visible (Hide)
#610: Ensure __init__
can be used when user implements __new__
.
Version 10.3 dropped support for calling __init__
, but that breaks
a number of popular projects. Reintroduce the ability to use __init__
when a class or one of its super classes contains a user implemenentation
of __new__
.
Code relying on the __new__
provided by PyObjC still cannot use
__init__
for the reason explained in the 10.3 release notes.
The release contains binary wheels for Python 3.13
PyObjC does at this time not support the experimental free threading
support in Python 3.13.
#569: Removed the workaround for a bug in Xcode 15.0
The workaround is no longer necessary, and caused problems when
building with the Command Line Tools development tools from Apple.
Updated SDK bindings for macOS 14.5
A minor change in the (currently private) tooling I use for
collecting the raw metadata resulted in minor fixes to the framework
bindings, in particular for metadata for a number of block and function
typed arguments and return values.
#275: It is now possible to create instances of Objective-C
classes by calling the class, e.g. NSObject()
instead of
NSObject.alloc().init()
.
The implementation of __new__
forwards calls to the underlying
SomeClass.alloc().init...()
pattern. In particular, all public init
methods are translated into sets of keyword arguments:
init
or initWith
from the start of the selector nameFor example, given a selector initWithX:y:
the __new__
method
will accept x, y
as keyword arguments, in that order.
Framework bindings have been updated with additional metadata to support
this pattern, and the sets of keyword arguments are automatically calculated
for subclasses in written in Python.
The limitation on the order of keyword arguments may be lifted in a future
version, it is currently present to keep the code closer to the Objective-C
spelling which should make it easier to look up documentation on Apple's
website.
For some Objective-C classes some of the init
and new
methods are not
available even if they are available in super classes. Those methods are
marked with NS_UNAVAILABLE
in Apple's headers.
As of this version these methods are also not available in Python code,
trying to call them will result in an exception.
To make methods unavailable in Python classes set these methods to None
,
e.g.:
class MyObject(NSObject):
init = None # NS_UNAVAILABLE
Added :func:objc.registerUnavailableMethod
,
:func:objc.registerNewKeywordsFromSelector
and
:func:objc.registerNewKeywords
to support the generic __new__
in framework bindings.
A limitation for registerUnavailableMethod
is that it is currently
not supported to reintroduce the method in a subclass, primarily because
that functionality is not needed for framework bindings.
Instantiating an Objective-C class by calling the class (e.g. invoking
__new__
) will not call __init__
even if one is defined.
The implementation of a subclass of NSObject
should always follow
the Objective-C convention for initializing using one or more
methods with a name starting with init
.
This can affect code that manually defines a __new__
method for
an Objective-C class, in previous versions that was the only way
to create instances in a Pythontic way.
NSArray
, NSMutableArray
, NSSet
and NSMutableSet
accepted
a sequence
keyword argument in previous versions. This is no longer supported.
It is still supported to create instances using a positional argument
for a sequence, e.g. NSArray([1, 2, 3])
.
NSData
, NSMutableData
, NSDecimal
, NSString
and NSMutableString
accepted a value
keyword argument in previous versions. This is no longer supported.
It is still supported to create instances using a positional argument,
e.g. NSData(b"hello")
.
NSDictionary
and NSMutableDictionary
do not support the
generic new interface because this conflicts with having a similar
interface to dict
for creating instances.
That is, NSDictionary(a=4, b=5)
is the same as NSDictionary({"a":4, "b":5})
,
and not like NSDictionary.alloc().initWithA_b_(4, 5)
.
Fix a number of warnings found by adding -Wpendantic
to the CFLAGS for
pyobjc-core
Fix undefined behaviour warnings:
Suppress the undefined behaviour warning about out of range values in
double to (unsigned) long long in the OC_PythonNumber
implementation
as these are unavoidable when matching NSNumber
behaviour.
Switch to using memcpy
instead of direct assignment in converting
plain C values to/from Python because "packed" structs might result
in accessing values through unaligned pointers.
Updated bindings for the macOS 14.4 SDK (Xcode 15.3)
Added bindings for the "BrowserEngineKit" framework on macOS 14.4 or later.
Add :func:obj.registerPathType
to register a Python type as a path like
type with PyObjC. By default only :class:pathlib.Path
is registered as such.
A minor backward compatibility issue is that instances of the registered types
will be written to NSArchive
and NSKeyArchive
archives as instances
of NSURL
and won't roundtrip back to the original Python type. This might
change in future versions of PyObjC, at least for :class:pathlib.Path
.
#589: Instances of :class:pathlib.Path
(and other types registered with
objc.registerPathType
) are bridged into Objective-C as instances of NSURL
.
This means that these types can be used as values passed to APIs expecting
a filesystem URL, e.g.:
path = pathlib.Path("/Applications/Numbers.app")
bundle = NSBundle.bundleWithURL_(path)
Fix some warnings in pyobjc-core when testing with Python 3.13a4.
Add support for NSBezierPathElementQuadraticCurveTo
in NSBezierPath.elementAtIndex_associatedPoints_
.
#595: Fix compilation error in pyobjc-framework-Cocoa
with a recent
deployment target.
Upgrade framework bindings for the macOS 14.2 SDK
#579: Make sure the install.py
and develop.py
scripts in the
repository work when run out of tree.
#577: os.fspath(someURL)
will not work with Cocoa URLs (NSURL, CFURLRef) that
refer to local filesystem paths. TypeError
will be raised for other URLs.
This enables using regular Python filesystem APIs with URLs that refer to
local filesystem paths.
#572: Fix compilation issue when building on macOS 13 or earlier
Fix build error on ancient macOS versions where clang doesn't support
-flto=thin
.
Add a workaround for a crash in pyobjc-core when running the testsuite
on macOS 10.14.
Fix some issues found while running the testsuite on macOS 10.9 to
macOS 13, instead of only testing on the latest macOS version. Most
issues found where problems in the testsuite itself, but not all.
Some of the changes skip tests on older macOS versions (10.12, 10.13
and 10.14) due to running into what appears to be crashing
platform bugs.
#581: Fix dependencies between framework binding packages
Fix build error with the current Python 3.13 alpha release (3.13a2).
Update bindings for macOS 14
Symbols newly introduced in macOS 14 were added to the existing bindings,
and the following new bindings were introduced:
Cinematic
MediaExtension
SensitiveContentAnalysis
Symbols
The "IMServicePlugIn" bindings are no longer available
The entire framework was deprecated in macOS 10.13 and removed in macOS 14.
The bindings can not be build using the latest SDK, and had (at best) limited
use.
#542: PyObjC 10 requires Python 3.8 and no longer supports Python 3.7
#547: Removed all MAC_OS_X_VERSION*
constants from objc
.
These constants are needed in practice (switch to :func:objc.available
to
check for platform availability), and caused unnecessary code churn.
The value for objc.options.deprecation_warnings
is now a string
instead of an integer.
#555: Fix unintended incompatibility with pytest in PyObjCTools.TestSupport
#295: The lazy loading machinery by default no longer uses
objc.ObjCLazyModule
, but uses module level __dir__
and
__getattr__
instead. The class :class:objc.ObjCLazyModule
is still
available, but is deprecated
As a side effect of this objc
is no longer an attribute of framework
binding packages (e.g Foundation.objc
is no longer a valid attribute).
Another side effect of this is that all attributes added by the import system
are now correctly present in the packages for framework bindings.
And a final side effect is that private symbols (prefixed with underscore) are
no longer imported from dependencies of framework bindings (more closely matching
the from dependency import *
behaviour that the lazy importer emulates.
Add attribute __framework_identifier__
to all framework bindings with the
identifier of the corresponding system framework.
#295: Introduce :func:objc.createFrameworkDirAndGetattr
to
create module level __dir__
and __getattr__
for use by
framework bindings.
#561: Tests now validate the bundle identifier value used in framework bindings.
This resulted in a number of changes to framework bindings with incorrect
bundle identifier values. This shouldn't affect user code because the
bundle loader falls back on the framework path when the identifier cannot be found.
#559: Avoid test failures in pyobjc-core when pyobjc-framework-Quartz is
not installed.
A number of classes can no longer be subclasses in Python because they are marked as non-subclassable
in the macOS 14 SDK (either directly or as "subclassing is deprecated":
CKAllowedSharingOptions
,
CKAsset
,
CKContainer
,
CKDatabase
,
CKDatabaseNotification
,
CKDatabaseSubscription
,
CKFetchRecordZoneChangesConfiguration
,
CKNotification
,
CKNotificationID
,
CKNotificationInfo
,
CKOperationConfiguration
,
CKOperationGroup
,
CKQuery
,
CKQueryCursor
,
CKQueryNotification
,
CKQuerySubscription
,
CKRecord
,
CKRecordID
,
CKRecordZone
,
CKRecordZoneID
,
CKRecordZoneNotification
,
CKRecordZoneSubscription
,
CKReference
,
CKServerChangeToken
,
CKShare
,
CKShareMetadata
,
CKShareParticipant
,
CKSubscription
,
CKSyncEngine
,
CKSyncEngineAccountChangeEvent
,
CKSyncEngineConfiguration
,
CKSyncEngineDidFetchChangesEvent
,
CKSyncEngineDidFetchRecordZoneChangesEvent
,
CKSyncEngineDidSendChangesEvent
,
CKSyncEngineEvent
,
CKSyncEngineFailedRecordSave
,
CKSyncEngineFailedZoneSave
,
CKSyncEngineFetchChangesOptions
,
CKSyncEngineFetchedDatabaseChangesEvent
,
CKSyncEngineFetchedRecordDeletion
,
CKSyncEngineFetchedRecordZoneChangesEvent
,
CKSyncEngineFetchedZoneDeletion
,
CKSyncEnginePendingDatabaseChange
,
CKSyncEnginePendingRecordZoneChange
,
CKSyncEnginePendingZoneDelete
,
CKSyncEnginePendingZoneSave
,
CKSyncEngineRecordZoneChangeBatch
,
CKSyncEngineSendChangesContext
,
CKSyncEngineSendChangesOptions
,
CKSyncEngineSentDatabaseChangesEvent
,
CKSyncEngineSentRecordZoneChangesEvent
,
CKSyncEngineState
,
CKSyncEngineStateSerialization
,
CKSyncEngineStateUpdateEvent
,
CKSyncEngineWillFetchChangesEvent
,
CKSyncEngineWillFetchRecordZoneChangesEvent
,
CKSyncEngineWillSendChangesEvent
,
CKSystemSharingUIObserver
,
CKUserIdentity
,
CKUserIdentityLookupInfo
.
The encoding of a number of basic types changes, in particular those
of CoreFoundation struct types and SIMD struct types. None of this
should affect user code.
objc.getClassList
now has an optional positional argument to
ignore classes with a name that aren't identifiers.
Some of the functionality in CoreFoundation was rewritten in Swift
in macOS 14, with Swift subclasses of NSArray
and NSDictionary
.
Those classes break an invariant of PyObjC: the superclass of the root
of the Swift class hierarchy changes when the class is instantiated
for the first time (from NSObject
to the correct superclass).
PyObjC 10 contains a workaround for this by ignoring these classes
unless they are needed to create a proxy for an instance (FB12286520).
Fix crash when the method signature retrieved from the Objective-C runtime
contains the class name for a method returning id
.
Remove old 32-bit support in metadata override files.
Restructure objc.simd
: The matrix types are now named simd_float3x3
instead of matrix_float3x3
, with the older name as an alias (to match
older system headers).
Fix crash when loading the libdispatch bindings on recent macOS versions
(at least macOS 13, possibly earlier)
dispatch.dispatch_source_t
is renamed to dispatch.dispatch_source_type_t
to match the type name in C code.
#569: Xcode 15 has a bug when using weak symbols and targeting older macOS
versions. Switch to the old linker when detecting Xcode 15.
Published by ronaldoussoren over 1 year ago
#549: Added warning objc.ObjCSuperWarning
that is used
to warn about classes that use argument-less super without binding that
name to objc.super
.
The correct code pattern is:
from Foundation import NSObject
from objc import super
class MyObject(NSObject):
def init(self):
self = super().init()
if self is None:
return None
...
return self
#549: Document that objc.super
must be used instead of
builtin.super
when calling superclass methods in a Cocoa subclass.
See the documentation <(https://pyobjc.readthedocs.io/core/super.html>
_
for more details.
#550: Add minimal pyproject.toml
to all subprojects
Recent versions of pip give a deprecation warning for projects without
a pyproject.toml
, and version 23.1 enabled the pyproject.toml
backend by default. Add a minimal pyproject.toml
to get a consistent
build regardless of the version of pip
#551: Fix crash in pyobjc-core when using Python 3.12a7.
#449: Added explicit tests for dealing with Objective-C categories
that are loaded while using classes from Python.
#552: Fix the version of macOS where the SafariServices framework is
present.
#552: Fixed some issues found by testing on a macOS 10.11 system
Trying to implement a method with SIMD types as arguments or return value
will now give a more useful error when the bridge does not support the
signature.
#554: Fix incomplete metadata for CoreMediaIO.CMIOObjectSetPropertyData
Fix incorrect metadata for
xpc.xpc_uuid_create
,
xpc.xpc_dictionary_set_uuid
,
xpc.xpc_array_set_uuid
,
JavaScriptCore.JSObjectMakeDeferredPromise
,
JavaScriptCore.JSValueIsEqual
,
JavaScriptCore.JSValueIsInstanceOfConstructor
,
JavaScriptCore.JSValueCreateJSONString
,
JavaScriptCore.JSValueToNumber
,
JavaScriptCore.JSValueToStringCopy
,
JavaScriptCore.JSValueToObject
,
Quartz.CGImageCreateWithJPEGDataProvider
,
Quartz.CGImageCreateWithPNGDataProvider
,
Quartz.CGImageMaskCreate
,
Quartz.CVBufferCopyAttachment
,
Quartz.CVMetalTextureCacheCreate
,
Quartz.CVMetalTextureCacheCreateFromImage
,
Quartz.CVOpenGLTextureCacheCreate
,
CoreMedia.CMAudioClockCreate
,
CoreMedia.CMAudioFormatDescriptionCreate
,
CoreMedia.CMBlockBufferGetDataPointer
,
CoreMedia.CMBlockBufferAccessDataBytes
,
CoreMedia.CMBlockBufferGetDataPointer
,
CoreMedia.CMAudioFormatDescriptionGetMostCompatibleFormat
,
CoreMedia.CMAudioFormatDescriptionGetRichestDecodableFormat
,
CoreMedia.CMSampleBufferCreateWithMakeDataReadyHandler
,
CoreMedia.CMSampleBufferCreateForImageBufferWithMakeDataReadyHandler
,
CFNetwork.CFNetServiceBrowserSearchForDomains
,
CFNetwork.CFNetServiceBrowserStopSearch
,
CFNetwork.CFNetServiceMonitorStop
,
CFNetwork.CFNetServiceRegister
,
CFNetwork.CFNetServiceResolve
,
CoreText.CTFontCreateCopyWithSymbolicTraits
,
CoreText.CTFontCreateCopyWithFamily
,
CoreText.CTFontCreateCopyWithAttributes
,
CoreMIDI.MIDISourceCreateWithProtocol
,
CoreMIDI.MIDISourceCreate
,
CoreMIDI.MIDISetupCreate
,
CoreMIDI.MIDIDestinationCreate
,
CoreMIDI.MIDIClientCreate
,
CoreMIDI.MIDIClientCreateWithBlock
,
CoreMIDI.MIDIOutputPortCreate
,
CoreMIDI.MIDIObjectGetStringProperty
,
CoreMIDI.MIDIObjectGetProperties
,
CoreMIDI.MIDIObjectGetIntegerProperty
,
CoreMIDI.MIDIObjectGetDictionaryProperty
,
CoreMIDI.MIDIObjectGetDataProperty
,
CoreMIDI.MIDIObjectFindByUniqueID
,
CoreMIDI.MIDIDestinationCreateWithProtocol
,
CoreMIDI.MIDIEndpointGetEntity
,
CoreMIDI.MIDIEntityGetDevice
,
CoreMIDI.MIDIEntityGetRefCons
,
CoreMIDI.MIDIEntitySetRefCons
,
DVDPlayback.DVDRegisterEventCallBack
,
DiskArbitration.DADiskMountWithArguments
,
GameController.NSDataFromGCExtendedGamepadSnapShotDataV100
,
HealthKit.HKAppleWalkingSteadinessClassificationForQuantity
,
IOSurface.IOSurfaceSetPurgeable
,
Network.nw_ethernet_channel_send
,
Removed Quartz.CGColorConversionInfoCreateFromListWithArguments
. This function
was already documented as unsupported, but was still present in the framework
wrapper.
Removed Quartz.CVPixelBufferCreateWithPlanarBytes
. This function requires a
manual binding, but was still present with a generic (and non-working) binding.
Removed CoreMedia.CMBufferQueueCreate
, CoreMedia.CMBufferQueueGetCallbacksForSampleBuffersSortedByOutputPTS
,
CoreMedia.CMBufferQueueGetCallbacksForUnsortedSampleBuffers
, CoreMedia.CMVideoFormatDescriptionGetH264ParameterSetAtIndex
,
CoreMedia.CMVideoFormatDescriptionGetHVECParameterSetAtIndex
,
These functions require a manual binding, but were still present with a generic (and non-working) binding.
Explicitly exclude definitions from CMIOHardwarePlugIn.h
from the CoreMediaIO
bindings.
Added deref_result_pointer
key to the metadata for a return value. Use this
when a callable returns a pointer to a single value (for example CMAudioFormatDescriptionGetMostCompatibleFormat
)
Removed unsupported functions from the ApplicationServices bindings (not named individually
due to the size of the list). Also fixed annotations for other ApplicationServices bindings.
Add manual binding for CFNetwork.CFNetServiceBrowserCreate
, CFNetwork.CFNetServiceSetClient
,
and CFNetwork.CFNetServiceMonitorCreate
.
Fix incompatibility with Python 3.12 beta 1.
warning:
Due to changes to the bytecode compiler the bridge will (incorrectly)
deduce that a method does not return a value (void
return in Objective-C)
when a method only contains return None
statements and no return
statements that return some other value (expressions or constants).
That is the following method is implied to return id
for Python 3.11 or
earlier, but is implied to return void
in Python 3.12.
def mymethod(self):
return None
This release continues the work on test coverage in pyobjc-core,
resulting in a number of minor bug fixes.
Added two options to the build_ext
command in the setup.py
of pyobjc-core:
--no-lto
: Disable link time optimization
--no-warnings-as-errors
: Disable -Werror
For struct bindings in frameworks the "in" operator no longer
swallows exceptions raised by the __eq__
method.
Improved handing of invalid type encodings for struct types.
Fix crash while handling a struct wrapper with an invalid
type encoding.
Fix handling of empty structs (such as struct foo { };
in
:func:objc.repythonify
.
The type for NSObject.pyobjc_instanceMethod
and
NSObject.pyobjc_classMethods
now supports the GC protocol
to avoid garbage collection issues when the value for these
properties is stored as an attribute (which introduces a
reference cycle)
PyObjC should work with Python 3.11 alpha release, starting
at alpha 6. Earlier alpha's are not supported due to reverting
a workaround for a bug that was fixed in alpha 6.
NSObject.alloc = 42
now fails. It was already impossible
to replace a selector by something else through instances
(NSObject.new().description = 42
raises).
Added :data:objc.ObjCPointer.typestr
with the same
value as :data:objc.ObjCPonter.type
. The latter is now
deprecated and will be removed in PyObjC 9.
Better error messages when a class implementing a protocol
inherits a method of the wrong kind ("class" vs. "instance").
The value of __slots__
in a class definition is now
kept in the created class (previous versions always set
the attribute to an empty tuple).
This is primarily useful when __slots__
is a :class:dict
that is used to document attributes.
Raise the correct exception when the name of a method is
not an ASCII string.
:func:objc.loadSpecialVar
now better enforces that the
module_globals argument is a Python dictionary.
Fixed a crash in :func:objc.loadSpecialVar
due to a
missing pointer dereference.
pip install pyobjc-framework-...
for a framework
that is not present on the current machine will now
give a better error message when the "wheel" package
is not installed.
Setting an integer option in :data:objc.options
to
a value of an incompatible type (such as a string) will
now raise an exception as intended, instead of breaking
the interpreter.
Trying to delete an attribute from :data:objc.options
now raises :type:AttributeError
instead of :type:TypeError
.
:class:objc.selector
now copies the default signature
from its argument when that argument is another :class:objc.selector
.
Until now this would raise an exception.
Added some missing error checking in calls to :c:func:PyObject_New
and :c:func:PyObject_GC_New
.
It is now possible to create an :class:objc.selector
from
a callable that is not a function or bound method. This may
require specifying the method signature in the call
to :class:objc.selector
.
For pyobjc-core the build_ext
command in setup.py
now includes the command-line option from the standaard
command, which means python setup.py build_ext -j 4
can now be used for parallel builds.
On my M1 laptop using python setup.py build_ext -j 8
halves the time needed to build the extension.
The test
command setup.py
now supports
the -v
option to print test cases while they are run,
in previoius versions this required using the --verbosity
option.
Improve error handling when dealing with "isHidden" selectors.
Added pyobjc_hiddenSelectors(classmethods)
to :class:objc.objc_class
This method returns a copy of the dictionary with "hidden" selectors,
that is Objective-C selectors that are hidden from view.
The method is primarily a debugging aid for development of
PyObjC itself.
#456: ApplicationServices.AXIsProcessTrustedWithOptions
and
Quartrz.CGPDFArrayGetObject
had incorrect metadata.
The testsuites for the various framework bindings now have a test
that does some basic checks on function and selector metadata. This
test found the problem with CGPDFArrayGetObject
.
Added :data:objc._C_ATOMIC
and :data:objc._C_COMPLEX
, both
extracted from the clang sources after finding some type encodings
that PyObjC could not decode.
:data:objc._C_ATOMIC
is ignored by PyObjC (for now), and
:data:objc._C_COMPLEX
is not yet supported.
#456: Fix internal error for _C_OUT
argument markup on
arguments that are CoreFoundation types.
This can only happen with invalid metadata definitions in framework
bindings, and earlier versions this resulted in an internal
assertion error. With this change the "output" argument is always
None
in the result.
#463: Fix metadata for a number of functions with a C string argument
The metadata for the following functions was changed to have
the correct type encoding for string argument, to fix issues with
using non-ASCII (byte) strings.
While fixing this issue I found problems with the metadata for these functions:
There's also a new test that checks for this problem in all
exposed functions.
Fix incorrect reset of the "inline_list" attribute of the lazy importer,
this could result in an incorrect TypeError when trying to access
an non-existing attribute after looking at __all__
.
Fix uniqueness of symbols exposed in the OpenDirectory bindings.
Unhide manual bindings for Security.SecKeychainFindGenericPassword and
Security.SecKeychainFindInternetPassword.
Published by ronaldoussoren over 2 years ago
This is a bug fix release.
#455: pip install pyobjc
on a macOS 12.2 machine tried
to install pyobjc-framework-ScreenCaptureKit
, which is
only can be installed on macOS 12.3 or later.
#456: Fix bad metadata for HIServices.AXIsProcessTrustedWithOptions
Wheels were build with Xcode 13.3 RC
There are no changes in framework bindings relative to
PyObjC 8.4 because there are no relevant API changes in
Xcode 13.3 RC.
The bindings for the Message and ServerNotification frameworks,
which were removed in macOS 10.9, will be removed in PyObjC 9.
Added bindings for ScreenCaptureKit (new in macOS 12.3)
Updated framework bindings for the macOS 12.3 SDK.
Based on Xcode 13.3 beta 3
Reverted a change in 8.3: It is once again not possible to
use the "is" operator to check if two proxies for an NSString
refer to the same Cocoa object.
The change in 8.3 changed long standng behaviour for mutable
strings and may have caused unintended problems.
#418: Added :class:typing.NewType
definitions to the
various framework bindings for all enum types in Cocoa
(such as NSComparisonResult
).
Using this it is now possible to annotate methods returning
such types, although it is not yet possible to type check
this.
For example:
.. sourcecode:: python
class MyObject(NSObject):
def compare_(self, other: NSObject) -> NSComparisonResult:
return NSOrderSame
The actual representation of enum types is provisional
and might change in the future.
#440: Added :class:typing.NewType
definitions to the
various framework bindings for all NS_STRING_ENUM
,
NS_TYPED_ENUM
and NS_TYPED_EXTENSIBLE_ENUM
types in Cocoa.
#432: Fix compatibility check when a class implements protocol NSObject
.
The following code used to fail the protocol implementation check:
.. sourcecode:: python
class AppDelegate( Cocoa.NSObject, protocols=[objc.protocolNamed("NSApplicationDelegate")]):
pass
The reason for this is that the type encodings for (at least) -[NSObject respondsToSelector:]
in the Objective-C runtime doesn't match the type encoding in @protocol(NSObject)
(the
former returns char
, the latter bool
). The compatibility check now handles trivial
differences like this.
#428: Class NSData
now implements the API from :class:bytes
. The methods that
return bytes in :class:bytes
also return bytes in NSData
. This may change in a
future version.
Class NSMutableData
now implements the API from :class:bytearray
as far as this
doesn't conflict with the native API. In particular, NSMutableData.copy()
returns
an immutable copy (instance of NSData
), use NSMutableData.mutableCopy()
to
create a mutable copy.
.. note::
The implementation is mostly suitable for fairly small amounts of data as
the Cocoa value is first copied into a Python value.
NSData([1,2,3])
and NSMutableData([1,2,3])
now work the same
as bytes([1,2,3])
and bytearray([1,2,3])
.
#334: Workaround for catetory on NSMutableArray that introduces a conflicting pop method
Some class in Cocoa can at times introduce an (undocumented) selector -pop
on subclasses of NSArray
, which conflicts with a convenience method that
emulates :meth:list.pop
. The version introduces a workaround for this by
adding the convenience method to all (statically known) subclasses of NSArray.
This is far from perfect, but fixes the problem for now.
Fix memory manager API misuse
PyObjC's :class:str
subclass used the python allocator API incorrectly,
causing an assertion failure when running tests with "python3 -Xdev
",
as well as a hard crash due to using the API without holding the GIL.
#445: Workaround for Python 3.11 support
Workaround for BPO-46891 <https://bugs.python.org/issue46891 >
_, which causes
a hard crash in the PyObjC testsuite. With this workaround the tests for
pyobjc-core pass with python 3.11a5, but this does result into adding some
implementation internals to the __dict__
of framework wrappers when using
Python 3.11
Fix build error on macOS 10.9
Fix :class:str
implementation invariant in the :class:objc.pyobjc_unicode
subclass. With this fix the string consistency checks in debug builds of
CPython pass.
Fix exception handling when passing a bytes object to a C function
with a byte buffer "inout" argument.
In PyObjC 7 and earlier it was possible to leave out "output" arguments when
calling a method with a Python implementation:
.. sourcecode:: python
class MyClass(NSObject):
@objc.typedSelector(b"@@:o^@")
def methodWithOutput_(self, a):
return 1, 2
o = MyClass.alloc().init()
print(o.methodWithOutput_())
This no longer works, it is always necessary to pass in all arguments, which
was already true for methods implemented in Objective-C. That is:
.. sourcecode:: python
print(o.methodWithOutput_(None))
This change both simplifies the PyObjC code base and was required to cleanly
implement vectorcall support (see the section on performance below).
Removed bindings for InterfaceBuilderKit
. This was a way to integrate
with InterfaceBuilder in old versions of Xcode, but support for that was
dropped before the release of Mac OS X 10.8.
Bindings for the Objective-C runtime API related to "associated objects" is
now enabled unconditionally. This will cause problems when running or building
on macOS 10.6 or earlier.
It is no longer possible to deploy to macOS 10.7 or earlier when you attempt to
create a formal protocol. Protocol creation already failed on those platform
due to lack of the required runtime API, and that will now result in a crash
because PyObjC no longer checks for availability of that runtime API.
#371: Remove manual bindings for a number of old CoreGraphics APIs
The following functions are no longer available:
CGDataProviderCreate
CGDataProviderCreateDirectAccess
These functions were removed as a public API in macOS 10.8, but were still
available through PyObjC through old backward compatibility code. That code has
now been removed.
For compatibility with Python's socket APIs functions that return a
"struct sockaddr" (either by reference or as a function result) will now
encode the IP address as a string and not a bytes object.
The (undocumented) API in pyobjc-api.h (used in some framework bindings to
integratie with pyobjc-core) has changed in an incompatible way, in particular
the API for "caller" functions now mostly mirrors the vectorcall convention.
Adding a method with a double underscore name will now raise an exception at
class definition time instead of silently not creating the Objective-C method.
.. sourcecode::
class AClass (NSObject):
...
def __foo_bar__(self, a, b, c):
pass
MethodNamesClass.__foo_bar__ = __foo_bar__
Before PyObjC 8 this would add a __foo_bar__
selector to the Python
representation of the class without adding a selector to the Objective-C class.
Use :func:objc.python_method
to mark this as a python-only function.
The module :mod:PyObjCTools.Signals
is deprecated and will be removed
in PyObjC 9.
:func:objc.initFrameworkWrapper
and :func:objc.parseBridgeSupport
are deprecated and will be removed in PyObjC 9.
These functions implement support for ".bridgesupport" XML files,
something that PyObjC hasn't used itself in a number of releases (in
part because system versions of those files are at best incomplete).
Most performance changes use features introduced in Python 3.9, performance
in older Python versions is unchanged except for the effects of general cleanup.
Implement the "vectorcall" protocol for :class:objc.function
, :class:objc.WeakRef
,
:class:objc.selector
, :class:objc.IMP
, :class:objc.python_method
.
This reduces the interpreter overhead for calling instances of these objects.
Implement Py_TPFLAGS_METHOD_DESCRIPTOR for :class:objc.selector
,
:class:objc.python_method
.
Use vectorcall in the method stub that forwards Objective-C calls to Python.
Convert internal calls into Python to the vectorcall protocol (pyobjc-core)
Add more optimized vectorcall implementation to :class:objc.function
,
:class:objc.IMP
and :class:objc.selector
for simpler callables.
In the current version "simpole enough" callables have a 8 or fewer
arguments, and none of those arguments are pass by reference. This will
change over time.
#391: Fix some spelling errors found by the
codespell <https://pypi.org/project/codespell/>
_ tool.
The codespell tool is also run as part of pre-commit hooks.
#296: use clang-format for Objective-C code
The Objective-C code for the various extensions has been reformatted
using clang-format, and this enforced by a pre-commit hook.
#374: Use pyupgrade to modernize the code base
This is enforced by a pre-commit hook.
#388: Added "nullability" attributes to Objectice-C sources for pyobjc-core.
This gives the compiler and clang static analyzer more information
that can be used to pinpoint possible bugs in the implementation. As a
side effect of this a number of internal checks were strengthened, although
most of them were for error conditions that should never happen.
That said, this change also found a number of places where Python reference
counts weren't updated properly, which may have led to refcount overflows
in long running programs.
Add more error checking to pyobjc-core to catch (very) unlikely error conditions.
This is a side effect of the previous item.
Updated framework bindings for macOS 12
New framework bindings for the following frameworks:
AudioVideoBridging (introduced in macOS 10.8)
DataDetection (introduced in macOS 12.0)
IntentsUI (introduced in macOS 12.0)
LocalAuthenticationEmbeddedUI (introduced in macOS 12.0)
MailKit (introduced in macOS 12.0)
MetricKit (introduced in macOS 12.0)
ShazamKit (introduced in macOS 12.0)
#318: Implement support for __class_getitem__
for Objective-C classes
The result of this is that effectively all Objective-C classes can be used
as generic classes, without runtime type checking. This is meant to be used
with optional type checking (for example MyPy)
Usage:
.. sourcecode:: python
def create_integers(count: int) -> NSArray[int]:
return NSArray[int].arrayWithArray_([i for i in range(count)])
.. note::
This requires typing stubs for framework bindings to be really useful,
and those do not yet exist.
#354: Add an option to install all framework bindings, including those not
relevant for the current platform. To use this:
.. sourcecode:: sh
$ pip install 'pyobjc[allbindings]'
#390: pyobjc-core is no longer linked with the Carbon framework.
Due to implicit dependencies this also required a change to the Metal
bindings: those now import AppKit instead of Foundation.
PyObjC only ships "Universal 2" wheels for Python 3.8 and later. Those work
with single-architecture builds of Python as well.
PyObjC 8 only ships with source archives and "univeral2" binary
wheels (Python 3.? and later). There are no longer "x86_64" binary wheels.
The AVFoundation bindings (in pyobjc-framework-AVFoundation
) now have
an install dependency on the CoreAudio bindings (pyobjc-framework-CoreAudio
).
This is needed for a new API introduced in macOS 12.
#371: Link extensions in the Quartz bindings to the Quartz frameworks
A number of C extensions in the Quartz bindings package were not
linked to a framework. Those now link to the Quartz framework.
#378: Fix raising ImportError
when doing from ApplicationServices import *
The root cause for this were private classes in system frameworks that contain
a dot in their name (for example Swift.DispatchQueueShim
. Those names are
both private and invalid attribute names.
Creating protocols that contain methods that have a method signature containing
PyObjC custom type encodings now works (those encodings are translated to
the corresponding Objective-C encoding.
Fix bindings for SKIndexCopyDocumentRefsForDocumentIDs
, that binding
didn't work due to a typo in the metadata.
#365: The PyObjCTools
namespace package no longer has an __init__.py
file in the source tree (that is, the tree switches to implicit namespace
packages instead of the older setuptools style for namespace packages).
This primarily affects testing with recent versions of pip/setuptools (which
seem to no longer install the __init__.py
file for namespace packages).
development-support/run-testsuite
now uses venv
instead of
virtualenv
. This removes a development dependency.
PR# 367: Tweak the code that calculates PyObjC_BUILD_RELEASE
in
the various setup.py files to deal with versions with more than two
labels (can happen when building using Xcode 13 beta)
PR by Eric Lin (Tzu Hsiang Lin), github user eric100lin.
PyObjCTest.TestSupport
now never uses "10.16" as the
OS release but always uses the actual platform version, even
when Python was compiled using an old SDK.
Adjusted PyObjC testcases to check for 11.0 instead of 10.16
now that testsupport uses the real platform version.
#385: Fix race condition the lazy importer
When two threads simultaneously try to get an attribute from a framework
binding one of them might fail with an attribute error because information
for resolving the name was removed before actually resolving the name.
Fix various issues with invalid indices in :class:objc.varlist
Fix support for AF_UNIX
in the support code for struct sockaddr
.
The implementation for opaque pointer types (such as the proxy for
'NSZone*') has switched to :c:func:PyType_FromSpec
.
The :meth:objc.FSRef.from_path
and :meth:objc.FSRef.as_pathname
,
methods now use the filesystem encoding instead of the default encoding.
C string. This shouldn't affect any code, both encoding default to UTF-8 on macOS.
Inheriting directly from :class:objc.objc_object
now raises :class:TypeError
instead of :class:objc.InternalError
. User code should always inherit from
a Cocoa class.
This release contains a lot of little fixes due to improving
test coverage of the C code in pyobjc-core. These are mostly fixes
for edge cases that don't happen in normal programs.
Reintroduce binary wheels for Python 3.6
PyObjC 8.x still supports Python 3.6, but I didn't ship binary wheels
until now.
I plan to explicitly remove support for Python 3.6 in PyObjC 9, which
will include updating package metadata to ensure that users of Python 3.6
will keep using PyObjC 8.x.
#414: [Python 3.10] The representation for C structures, like
Foundation.NSPoint
now have a __match_args__
attribute, which means
it is now possible to use positional arguments to these types in match expressions.
For example:
.. sourcecode:: python
from Foundation import NSPoint
value = ...
match value:
case NSPoint(0, _):
print("On the Y axis")
The internal extension API between framework bindings and pyobjc-core has
been cleaned up a little. Because of this extensions need to be
recompiled for this version.
:func:objc.allocateBuffer
is deprecated, use :class:bytearray
instead
This function has always returned a bytearray object in Python 3 and it
no longer necessary.
As a side effect of this change the function is now implemented in Python
instead of C.
The private function objc._dyld_shared_cache_contains_path
is now
always available, and unconditionally returns :data:False
on systems without
a shared library cache.
The private function objc._setClassExtender
is now implemented in Python
and will be removed in PyObjC 9.
Removed private function objc._typestr2typestr
.
This function was untested and is no longer used by PyObjC.
Removed the selector supportsWeakPointers
from a number of classes.
This method may have been needed during Apple's transition to ARC, but is
no longer document and I've never seen it called during testing on recent
versions of the OS.
Furthermore the custom implementation of retain
and release
in PyObjC
is a thin wrapper around the default one with additional locking to avoid
race conditions during deallocation.
:func:objc.recylceAutoReleasePool
will now restore the global release pool
when called after calling :func:objc.removeAutoreleasePool
.
Removed objc.FSSpec
This is a wrapper for a C type that's only usable in 32-bit code, PyObjC
no longer supports 32-bit.
The default implementation of -copy
for subclasses of Objective-C
classes that implemented -copy
(needed to adjust Python attributes)
didn't consider that the superclass implementation of -copy
may
return an instance of a different class. This caused a hard crash.
The easiest way to trigger this bug: Create a subclass of NSMutableData
in Python, create an instance of that class and call the copy
method.
The module PyObjCTools.TestSupport
was modernized a little
This most visible part of this is that a number of functions and assertion
method have been removed because they have a better alternative in the
:mod:unittest
library.
#404: Instances of the Python represention of C structs can now be pickled.
That is, instances of AppKit.NSPoint
, Foundation.NSRange
, etc. can
be pickled. The exception are a number of types in the CoreAudio bindings
that have manual wrapper types instead of the generic support in pyobjc-core.
Switch to :c:func:PyCapsule_Import
to load the PyObjC API object in
extension modules.
Fix crash when calling objc.FSRef.from_pathname()
with a path
that cannot be encoded in the filesystem encoding (UTF-8).
Fix name of opaque pointer type wrappers (such as Foundation.NSZonePtr
)
The "name" and "qualname" attributes were correct, but the
corresponding slot in the C struct of the type could point to
no longer valid memory.
Function :func:objc.registerABCForClass
now actually works
Fix bug in lazyloader where fetching the module's __all__
could
raise :exc:AttributeError
for some particular constants.
#317: Cleanup code dealing with libffi closures APIs on various versions
of macOS.
If fetching the __pyobjc_object__
attribute during conversion from
Python to Objective-C raisea an exception other than :exc:AttributeError
the conversion will fail.
In previous versions the attribute was ignored when this happens.
Fix error in __str__
and __repr__
of an Objective-C instance
when the class' description
selector returns nil
.
Fixed crash in conversion of an Objective-C exception to a Python
exception when the exception name is NULL
.
Type encoding that ends with an incomplete pointer definition will
now raise an error earlier, in particular before the first time the
callable is used.
Using a value for the metadata dict of functions and selectors that
is not a :class:dict
now raises an exception instead of being silently
ignored.
The "suggestion" function metadata was ignored for :class:objc.function
instances using the fast FFI variant.
Deprecating the function returned by an API exposed through :class:objc.function
would cause a crash.
Fix value of the "deprecated" key in the result of __metadata__()
for
callables that are deprecated in a macOS version.
Loading metadata for a function with more than 63 arguments would
crash the interpreter.
Note that calling such function is not supported even with this bugfix.
#406: The "docstring" field in the function list argument for
:func:objc.loadBundleFunctions
was effectively ignored. It is now
part of the document string (__doc__
) of the :class:objc.function
object.
Actually implemented cyclic GC support in :class:objc.python_method
.
Fix crash when calling -[NSObject dealloc]
, -[NSObject retain]
or -[NSObject release]
though an :class:objc.IMP
, for example:
.. sourcecode:: python
anObject = NSObject.alloc().init()
retain = anObject.methodForSelector_("retain")
retain(anObject)
Tests in pyobjc-core better check the message of raised exceptions
This resulted in some minor changes in messages, this should not affect
code using PyObjC.
Fix the __name__
and __repr__
result for the exact class
:class:objc.objc_object
.
Fix use of uninitialized variable in the code that converts a C struct
from Objective-C to a Python tuple.
Added :func:PyObjCTools.TestSupport.no_autorelease_pool
to disable
autorelease pool management by the test runnner for a specific test.
NSMutableArray.insert(idx, value)
would fail when idx
is beyond
the length of the array. It now behaves the same as :meth:list.insert
,
the item will be appended to the array.
Change the way type specific class methods are added to :class:objc.ivar
.
This changes the way class methods are added to :class:objc.ivar
to
be more correct in the CPython interpreter.
#425: Fix CoreMIDI bindings
The CoreMIDI is a wheel with a limited ABI tag, but one of the two
extensions was build without using the limited ABI, resulting in a wheel
that worked only for one python version.
This release contains a lot of small fixes dueo to the continued improvement
of test coverage for the C code in pyobjc-core.
Backward incompatible change:
-[OC_PythonDictionary setObject:value forKey:[NSNull null]]
now sets
key :data:None
in the Python dictionary instead of NSNull.null()
.
This is for consistency with -[OC_PythonDictionary objectForKey:]
and
other collection classes. Getting and setting key [NSNull null]
now
actually works.
Backward incompatible change:
-[OC_PythonDictionary removeObjectForKey:]
now raises NSInvalidArgumentException
instead of Python's KeyError
for missing keys. This matches the documented
behaviour of NSDictionary
.
Backward incompatible change:
-[Protocol descriptionForClassMethod:]
now only accepts selector names
(such as b"description"
) as its argument, not instances of
:class:objc.selector
. This matches the behaviour of other methods
with an argument of the C type SEL
.
:func"objc.namedSelector
and :func:objc.typedSelector
now also work when
the decorated function is a :func:classmethod
.
Fix build problem on macOS 10.14 or earlier
The Objective-C proxy for a python :class:int
is now always OC_PythonNumber
,
in previous versions instances were proxied as NSNumber
when the
value was in the range of an unsigned long long
that's outside of the
range of a (signed) long long
(that is, a value between
2**63
and 2**64
).
Two NSString*
values in Objective-C are now proxied to the
same :class:objc.pyobjc_unicode
instance when the two pointers are
equal in Objective-C.
That is, given NSString* value1
and NSString* value2
value1 == value2
in Objective-C can be replaced by
value1 is value2
in Python. In older versions of PyObjC
this invariant was not maintained, requiring more involved code to
check if two strings represent the same object.
This invariant was already maintained for other instances of other
Objective-C classes.
The proxy for python's :class:bytearray
(and other writable buffers) now
supports the mutableBytes
method in Objective-C.
As a side effect of this OC_PythonData
is now a sublcass of
NSMutableData
instead of NSData
.
Fixed retrieving an :class:bytearray
value from a Cocoa archive
In previous versions this resulted in garbage data.
Instances of :class:bytearray
can now be included in "secure" Cocoa archives
Remove -[OC_PythonArray getObjects:inRange:]
, it is not part of the
regular NSArray
interface and was never used.
The proxy for python datetime objects was rewritten to be a lot simpler.
User visible changes:
The new implementation is more correct, the old implementation truncated
timestamps at whole seconds.
Calculating in Objective-C (such as calling -[NSDate dateByAddingTimeInterval:]
will now always result in an NSDate
value, not a Python value.
The proxy code now calls the "timestamp" method instead of "strftime" during
conversion from Python to Objective-C.
Adding :class:datetime.datetime
and :class:datetime.date
instances to an
archive now works, both for keyed and classic archives.
For the exact types :class:datetime.datetime
and :class:datetime.date
the encoding
is compatible with that of NSDate
and supports NSSecureCoding
as long as the
values are not timezone aware.
When communicating with pure Objective-C code any timezone information will be lost.
Note that both :class:datetime.datetime
and :class:datetime.date
are
represented as an NSDate
in Objective-C land, even though this Objective-C has
semantics of the latter class don't fully match that of the Cocoa class.
Fix python internal error when the "module_globals" argument to
:func:objc.loadBundleFunctions
is not a :class:dict
.
Fix the result of :func:inspect.signature
for :class:objc.IMP
.
In previous versions this included the implicit "selector" argument that isn't used
by Python callers.
Avoid crash when trying to load a "magic" cookie CoreFoundation value for a
type unknown to the PyObjC bridge.
Removed -[OC_PythonObject pyObject]
.
The method is no longer used by PyObjC itself, and these proxy objects are considered
a private API that may change at any time.
Removed +[OC_PythonObject classForUnarchiver]
This method was present for compatibility with the NSObject
interface, but isn't
actually part of Cocoa.
-[OC_PythonObject methodSignatureForSelector:]
and
+[OC_PythonObject methodSignatureForSelector:]
now return nil
instead of
raising an exception when the queried selector does not exist. This matches
the behaviour of NSObject
.
Fix the metadata in the bindings for DiscRecording, Intents, SceneKit, and libdispatch
to ensure that the __all__
variable actually works.
Eliminated usage of sscanf in pyobjc-core
A possible user visible change is that the use of sscanf
to parse an IPv4 address has been replaced by a call
to inet_pton()
, which may affect different representations
of an IPv4 address.
OC_PythonSet
now epxlictly calls set related methods instead
of using C-API functions like :func:PySet_Clear
. This simplifies
the pyobjc-core code, and gives fewer problems with set subclasses.
Fix the buffer size used to for "struct sockaddr" arguments
Added objc._C_CFRange
and objc._C_NSRange
with the type
encodings of the C types CFRange
and NSRange
.
Functions and methods where the length of a C array argument is passed
in another argument (such as int function(int* buffer, size_t bufsize)
)
now also work when the argument with the size is a pointer to
a CFRange
or a pointer to a char
.
A :class:memoryview
of an NSMutableData
instance is now writable.
Fix crash when trying to create an :class:objc.informal_protocol
with
a sequence of selectors that contains a value that isn't an instance
of :class:objc.selector
.
#435: Fix build problem with Xcode 13.3
Xcode 13.3 introduces a new warning in -Wall
: -Wunused-but-set-variable
,
and this found some code quality issues with PyObjC.
Published by ronaldoussoren over 3 years ago
With WWDC and beta of a new major release of macOS approaching fast it is high time to push out a new release for PyObjC. PyObjC 7.3 is primarily a bugfix release, with one minor feature.
I expect this to be the last release for PyObjC 7.x and will start working on PyObjC 8 soon.
issue 356: Explicitly error out when building for unsupported architectures
"python setup.py build" will now fail with a clear error when
trying to build PyObjC for a CPU architecture that is no longer
supported (such as 32-bit Intel)
issue 319: Use memset instead of bzero in C code to clear memory
Based on a PR by GitHub user stbdang.
issue 348: Fix platform version guard for using protocols in MetalPerformanceShaders bindings
issue 344: Fix test for CFMessagePortCreateLocal
The tests didn't actually test calling the callback function
for CFMessagePortCreateLocal.
issue 349: Change calls to htonl in pyobjc-core to avoid compiler warning
The original code had a 32-bit assumption (using 'long' to represent
a 32-bit value), and that causes problems for some users build from
source.
issue 315: Fix binding for SecAddSharedWebCredential
(Security framework)
Trying to use this function will no longer crash Python.
issue 357: Calling Metal.MTLCopyAllDevices()
no longer crashes
The reference count of the result of this function was handled incorrect,
causing access to an already deallocated value when the Python reference
was garbage collected.
issue 260: Add manual bindings for AXValueCreate and AXValueGetValue in ApplicationServices
Calling these crashed in previous versions.
issue 320, 324: Fix the type encoding for a number of CoreFoundation types in the Security bindings
issue 336: Add core support for "final" classes
It is now possible to mark Objective-C classes as final,
that is to disable subclassing for such classes.
This is primarily meant to be used in framework bindings for
matching Objective-C semantics.
The "final" feature adds two new APIs:
A keyword argument "final" when defining a new class
class MyClass (NSObject, final=True):
pass
An read-write attribute __objc_final__
on all subclasses of NSObject.
Note that this is a separate concept from typing.final
.
#311: Build for the Metal bindings failed on macOS 10.14
#309: Fix incompatibility with macOS 11 in framework loader
Another attempt at giving a nice error message when trying to install on
platforms other than macOS.
The classifiers now correctly identify supported Python versions
Issue #299: Ensure package 'pyobjc' won't try to build the PubSub bindings on macOS 10.15
Reported by Thomas Buchberger
Minor tweaks to build and pass tests on macOS 10.14 with the latest Xcode
that can be installed on that version of macOS.
Issue #300: Fix SystemError in block edge case
PyObjC raised a SystemError when converting a callable into
an ObjC block when the callable is a bound method without
positional arguments.
Issue #275: Fix crash on catalina caused by writing to read-only memory.
Patch by Dan Villiom Podlaski Christiansen
PR #302: Make sure the SDK detection works when the version is not in the SDK name
Patch by Joshua Root
There were no SDK updates in Xcode 11.5 and Xcode 11.6 (beta)
The project has moved from Bitbucket to Github
Remove most remnants of Python 2 support
Clean up code quality issues found using flake8
Add pre-commit hook to run black on all Python code.
#290: Fix protocol conformance testing when explicitly implementing a protocol
Before this bugfix a class explicitly conforming to a protocol could not
implement any method that wasn't declared in the protocol, the bridge would
erroneously raise an exception when checking the additional method.
Issue reported by Georg Seifert.
#289: Fix Python 3 issues in PyObjCTools.Conversion
Reported by vinolin asokan.
PyObjCTools.Conversio.propertyListFromPythonCollection
didn't
recursively convert members of lists and tuples.
PyObjCTools.Conversio.propertyListFromPythonCollection
and
PyObjCTools.Conversio.pythonCollectionFromPropertyList
now
support sets.
Update metadata for Xcode 11.4 (beta 2)
Added bindings for framework AutomaticAssessmentConfiguration.framework
introduced in macOS 10.15.4
#298: In some cases the compiler uses the type encoding "^{NSObject=#}"
instead of "@".
Reported by Georg Seifert.
#264: Added bindings for the Metal framework (new in macOS 10.11)
Most framework bindings now use the limited ABI for the included C extensions,
reducing the number of wheels that are needed. The exception are
the bindings for Cocoa, Quartz and libdispatch, those use functionality not
available in the limited ABI.
The bridge itself (pyobjc-core) still uses the full CPython API.
The CoreAudio bindings also don't use the limited ABI for now, those
need more work to work with that ABI.
Issue #50: Accessing Objective-C methods on "magic cookie" variables,
like LaunchServices.kLSSharedFileListItemLast
would crash the interpreter.
This affected code like::
from LaunchServices import kLSSharedFileListItemLast
kLSSharedFileListItemLast == kLSSharedFileListItemLast
dir(kLSSharedFileListItemLast)
kLSSharedFileListItemLast.compare_
Added a decorator "python_method" than can be used to decorate methods that should
not be registered with the Objective-C runtime and should not be converted to a
Objective-C selector.
Usage::
class MyClass (NSObject):
@python_method
@classmethod
def fromkeys(self, keys):
pass
This makes it easier to add a more "pythonic" API to Objective-C subclasses without
being hindered by PyObjC's conventions for naming methods.
Issue #64: Fix metadata for Quartz.CGEventKeyboardSetUnicodeString
and Quartz.CGEventKeyboardGetUnicodeString
.
Issue #77: Passing a bound selector as a block argument failed when the block
was actually called because the trampoline that calls back to Python accidently
ignored the bound self
argument.
Issue #76: It is now possible to pass None
to a method expecting a block
argument, as with normal object arguments the Objective-C method receives
a nil
value.
Python integer values with values between 2 ** 63 and 2**64 are now proxied
as plain NSNumber objects, not as using PyObjC specific subclass of NSNumber,
to avoid a problem with writing them to binary plist files.
This is a workaround and will likely be changed in some future version.
inspect.signature
works for all functions and methods implemented in C,
when using Python 3.4 or later.
The module PyObjCTools.NibClassBuilder
is not longer available. It only worked
with ancient versions of Interface Builder (pre-Xcode)
The wrapper type for opaque pointers didn't have a "module" attribute,
which breaks code that (correctly) assumes that all types have such an attribute.
Archiving now supports nested definitions and method references, simular
to the support of those added to pickle protocol 4 in Python 3.4.
Encoding nested classes requires support for the __qualname__
attribute,
and hence requires Python 3.3. Decoding should work with earlier python
versions as well.
Addd objc.autorelease_pool
, a context manager for managing an
autorelease pool. Usage::
with objc.autorelease_pool():
pass
This is equivalent to::
_pool = NSAutoreleasePool.alloc().init()
try:
pass
finally:
del _pool
Added objc.registerABCForClass
to make it possible to register
a class with a number of ABC classes when the class becomes available.
NSDecimalNumber
can now be instantatiated as a normal Python object::
value = NSDecimalNumber(4)
NSData
and NSMutableData
can now be instantiated as a normal
Python object::
value = NSData(someBytes)
or::
value = NSData()
NSDecimal
now coerces the other value to NSDecimal
in coercions.
Because of you can now order instances of NSDecimal
and int
.
PyObjCTools.KeyValueCoding.ArrayOperators
and
PyObjCTools.KeyValueCoding.arrayOperators
were accidently public
names in previous releases, and are now removed. Use the array operators
in the KVC protocol instead.
Restructured the "convenience" method code. This shouldn't have user
visible effects, but makes the code easier to maintain.
objc.addConvienceForSelector
no longer exists, it isn't possible
to provide this functionality with the current implementation of the
bridge.
The build of pyobjc-core can now be configured by editing setup.cfg (or
providing arguments to the build_ext command), instead of editing the
setup.py file.
Currently the following options are availabel for the build_ext command:
--use-system-libffi
: When this option is used the build will use
/usr/lib/libffi.dylib instead of the embedded copy of libffi. The latter
is the default is and is better tested.
--deployment-target=VAL
: The value of MACOSX_DEPLOYMENT_TARGET
to use,
defaults to the deployment target used for building Python itself
--sdk-root=VAL
: Path to the SDK root used to build PyObjC, or "python" to
use the default SDK selected by distutils. The default is to use the
most recent SDK available.
The lazy importer has smarter calculation of the __all__
attribute,
which should speed up 'from Cocoa import *'.
BUGFIX: using a method definition with only *args
and **kwds
used
to crash the interpreter, the now once again raise a TypeError exception.
The metadata for pyobjc-framework-Accounts was incomplete, fixed that.
:func:objc.callbackFor
now also adds a metadata method to decorated
functions. This is primarily to make it easier to test the metadata values.
The typestr attribute of opaque pointer types is now a byte string,
in previous versions this was an instance of :class:str
(this only affects
Python 3 support)
The JavaScriptCore bindings (in pyobjc-framework-WebKit) are now more usable
because types like "JSValueRef" are now exposed to Python (they were missing
due to incomplete metadata).
Exclude a number of keys from the metadata dictionary when they have the
default value (in the result from the metadata() method on methods
and functions)
The "lazy" modules used by framework wrappers now always have a __loader__
attribute (as required by PEP 302). The value can be :data:None
when there
is no explicit loader (such as when importing from the filesystem in Python 3.2
or earlier).
Method (and function) metadata is stored in a more compact manner, reducing the
memory use of PyObjC applications.
Removed support for hiding "protected" methods, :func:objc.setHideProtected
is gone,
it complicated the code without real advantages.
Reasons for this:
There were some conflicts because a class implemented two selectors that caused
the same python method to be added to the class dict. Which one was added
was basicly random.
The functionality required PyObjC to maintain a full dict for classes, even
when most Cocoa methods were never called. Ensuring that the contents of dict
is correct in the face of Objective-C categories and class patches required some
very expensive code.
As a side effect of this some classes may no longer have the convenience methods they
had in earlier releases (in particular classes that are not mentioned in Apple's
documentation).
Issue #3: The bridge now lazily looks for Objective-C methods as they are used from Python, instead
of trying to maintain a class dict that mirrors the method list of the Objective-C
class.
Maintaining the dict was very expensive, on every method call the bridge would
check if the method list had changed and there is no cheap way to perform that check.
.. note::
I haven't done performance tests at this time, it is not yet clear if this work will
make the bridge more efficient or that there are other more important bottlenecks.
The default translation from a python name to a selector was slightly changed:
double underscores inside the name are no translated to colons, that is 'foo__bar_' is translated to 'foo__bar:', not 'foo::bar:'
if the Python name start with two uppercase letters and an underscore, that first underscore is not translated into
an colon. Two leading capitals are often used as a way to add some kind of namespacing
to selector names (and avoid conflicts when a method with the same name is added later by the library provider)
Added new method to NSString, it is now possible to explictly convert a python string to a Cocoa
string with NSString(someString)
Added eq and ne methods to native selector objects, which mean you can now
check if two method objects are the same using 'sel1 == sel2'. This works both for bound
and unbound selectors.
NSData.bytes() could raise an exception on some version of Python 3 when the data object is empty.
The function now returns an empty bytes object instead.
NSMutableData.mutableBytes() raises an exception when the data object has a 0-sized buffer.
(see also the previous bullet)
Add attribute objclass to :class:objc.selector
instances as an alias for definingClass. The name
objclass is used by builtin method objects for the same purpose as definingClass.
The new attribute is needed to ensure that help(NSObject)
works (although all methods are shown as
data descriptors, not methods)
:classobjc.selector
no longer implements set, which means it is now classified as a method
descriptor by the :mod:inspec
module, which gives nicer output in :mod:pydoc
.
This doesn't change any functionality beyond that, it is still possible to overwrite methods and not
possible to delete them.
:class:objc.native_selector
and :class:objc.function
now have a (minimal) docstring with information
object. This makes :func:help <pydoc.help>
for Cocoa classes and functions more useful.
As a side-effect of this the docstring is no longer writeable.
.. note::
The docstring show the interface of a block with a function prototype instead of the proper
C declaration, that makes the implementation slightly easier and the function prototype syntax
is slightly easier to read for users that aren't C experts.
:class:objc.selector
, :class:objc.function
and :class:objc.IMP
now have an implementation for
the "signature" property when using Python 3.3 or later. This makes it possible to use
:func:inspect.signature
with these objects.
It should now be possible to write tuples with more than INT_MAX elements to an NSArchive. Those archives
cannot be read back by older versions of PyObjC (or python running in 32-bit mode), but archives that
contain only smaller tuples can be read back by earlier versions.
Issue #38: Struct wrappers and opaque pointer types now implement support for :func:sys.getsizeof
,
as do :class:objc.FSRef
, :class:objc.FSSpec
, and Objective-C classes.
The size of Objective-C instances is not entirely correct, and cannot be. The :func:sizeof <sys.sizeof>
function
only reports the size of the proxy object and the basic size of the Objective-C object. It does not
report additional buffers used by the object, which for example means that a too low size is reported
for Cocoa containers like NSArray.
Opaque pointer objects now have a method "c_void_p" that returns a :class:ctypes.void_p
for
the same pointer.
Added an API to "pyobjc-api.h" that makes it easier to explicitly load function references in
manual function wrappers. This replaces the compiler support for weak linking, which was needed
because weak linking did not work properly with clang (Xcode 4.5.1). This also makes it possible
to compile in support for functions that aren't available on the build platform (in particular, when
building on 10.8 the Quartz bindings now contain support for some functions that were dropped in 10.8
and which will be available through pyobjc when deploying to 10.7)
The framework wrappers no longer export a "protocols" submodule. Those submodules were deprecated in
2.4 and did not contain information that is usefull for users of PyObjC.
Dropped the "objc.runtime" attribute (which was deprecated in PyObjC 2.0)
Dropped depcreated APIs objc.pluginBundle, objc.registerPlugin. Py2app has used a
different mechanism for years now.
Dropped deprecatd APIs: objc.splitStruct, objc._loadFunctionList. Both have
been replaced by newer APIs in PyObjC 2.4.
Foundation's NSDecimal type is exposed in the objc module as well.
This was done to remove a dependency from the pyobjc-core package to pyobjc-framework-Cocoa.
The type :class:objc.NSDecimal
is now an immutable type, just like
:class:decimal.Decimal
and other Python value types.
Because of this the interface of Foundation.NSScanner.scanDecimal_
has changed, in
previous versions it is used as::
dec = Foundation.NSDecimal()
ok = scanner.scanDecimal_(dec)
In the current version it is called just like any other method with an output argument::
ok, dec = scanner.scanDecimal_(None)
The C code is more careful about updating Python reference counts, in earlier versions
it was possible to trigger access to a field in a datastructure that was being deallocated
because the calls to :c:macro:Py_DECREF
for the field happened before setting the
field to :c:data:NULL
or a new value. This could then result in a hard crash due to
accessing freed memory.
Bugfix: objc.NSDecimal(2.5) works with python 3 (caused a confusing
exception due to buggy code before).
Bugfix: the support for :func:round <__builtin__.round>
for :class:objc.NSDecimal
always rounded down, instead of using the normal rounding rules used by other
methods.
PybjC no longer supports the CoreFoundation bindings in the "Carbon.CF" module
in the standard library for Python 2. The "Carbon.CF" module is not present
in Python 3, and is unmaintained in Python 2.
The 'struct sockaddr' conversion code now understands the AF_UNIX address family.
The function "objc.setSignatureForSelector" has been removed (and was deprecated
Issue #86: Fix installation issue with setuptools 3.6.
Issue #85: Remove debug output from the wrapper for NSApplicationMain
.
Issue #82: NSArray.iter was accedently removed in PyObjC 3.0
PyObjCTools.Debugging didn't work properly on recent OSX versions (at least OSX 10.9)
because /usr/bin/atos
no longer worked.