Skip to content

Commit

Permalink
Backport for a925b8c (with additions)
Browse files Browse the repository at this point in the history
Issue #623: Don't lowercase the first character of the first keyword
argument for ``__new__`` when the segment only contains upper case
characters.

Before this change ``initWithURL:`` mapped to an ``uRL`` keyword argument,
with this fix the keyword argument is named ``URL``.
  • Loading branch information
ronaldoussoren committed Oct 27, 2024
1 parent e5aa375 commit 093b605
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 1 deletion.
11 changes: 11 additions & 0 deletions docs/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,17 @@ Version 10.3.2
Recent versions of setuptools broke the "test" command, the full command
has been reimplemented as part of PyObjC.

* :issue:`627`: Fix build issue when deployment target is 15.0 or later.

* :issue:`623`: Don't lowercase the first character of the first keyword
argument for ``__new__`` when the segment only contains upper case
characters.

Before this change ``initWithURL:`` mapped to an ``uRL`` keyword argument,
with this fix the keyword argument is named ``URL``.

Fix by user rndblnch on github

Version 10.3.1
--------------

Expand Down
4 changes: 3 additions & 1 deletion pyobjc-core/Lib/objc/_transform.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,9 @@ def _selectorToKeywords(selector):
parts = selector.split(":")[:-1]
if parts[0].startswith("With"):
parts[0] = parts[0][4:]
parts[0] = parts[0][:1].lower() + parts[0][1:]

if len(parts[0]) == 1 or (len(parts[0]) > 1 and not parts[0].isupper()):
parts[0] = parts[0][:1].lower() + parts[0][1:]

return tuple(parts)

Expand Down
9 changes: 9 additions & 0 deletions pyobjc-core/Modules/objc/test/genericnew.m
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,15 @@ -(instancetype)initWithValue:(NSObject*)v
return self;
}

-(instancetype)initWithURL:(NSObject*)v
{
self = [super init];
if (!self) return nil;

value = [v retain];
return self;
}

-(instancetype)initWithFirst:(NSObject*)first second:(NSObject*)second
{
self = [super init];
Expand Down
4 changes: 4 additions & 0 deletions pyobjc-core/PyObjCTest/test_generic_new.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
NSObject = objc.lookUpClass("NSObject")

objc.registerNewKeywordsFromSelector("OC_GenericNew", b"initWithValue:")
objc.registerNewKeywordsFromSelector("OC_GenericNew", b"initWithURL:")
objc.registerNewKeywordsFromSelector("OC_GenericNew", b"initWithFirst:second:")
objc.registerNewKeywordsFromSelector("OC_GenericNewChild", b"initWithX:y:")
objc.registerNewKeywordsFromSelector("OC_GenericNewChild2", b"initWithX:y:z:")
Expand Down Expand Up @@ -151,6 +152,9 @@ def test_base(self):
v = OC_GenericNew(value=42)
self.assertEqual(v.value(), 42)

v = OC_GenericNew(URL=99)
self.assertEqual(v.value(), 99)

v = OC_GenericNew(first=1, second=2)
self.assertEqual(v.value(), ["first-second", 1, 2])

Expand Down

0 comments on commit 093b605

Please sign in to comment.