Skip to content

Commit 2ba462f

Browse files
authored
Remove IPY3 constant (#707)
1 parent b27af91 commit 2ba462f

5 files changed

Lines changed: 3 additions & 139 deletions

File tree

Directory.Build.props

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@
103103
<DebugType>portable</DebugType>
104104
<Optimize>true</Optimize>
105105
<CheckForOverflowUnderflow>false</CheckForOverflowUnderflow>
106-
<DefineConstants>$(Features);$(SignedSym);IPY3;TRACE</DefineConstants>
106+
<DefineConstants>$(Features);$(SignedSym);TRACE</DefineConstants>
107107
</PropertyGroup>
108108

109109
<!-- Debug -->
@@ -113,6 +113,6 @@
113113
<Optimize>false</Optimize>
114114
<!-- TODO: Python & zlib.net need some work -->
115115
<CheckForOverflowUnderflow>false</CheckForOverflowUnderflow>
116-
<DefineConstants>$(Features);$(SignedSym);IPY3;DEBUG;TRACE</DefineConstants>
116+
<DefineConstants>$(Features);$(SignedSym);DEBUG;TRACE</DefineConstants>
117117
</PropertyGroup>
118118
</Project>

Src/IronPython.Modules/_collections.cs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1101,11 +1101,7 @@ public PythonTuple __reduce__(CodeContext context) {
11011101
PythonTuple.MakeTuple(default_factory),
11021102
null,
11031103
null,
1104-
#if IPY3
11051104
Builtin.iter(context, PythonOps.Invoke(context, this, nameof(PythonDictionary.items)))
1106-
#else
1107-
iteritems()
1108-
#endif
11091105
);
11101106
}
11111107
}

Src/IronPython/Runtime/DictionaryOps.cs

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -73,22 +73,6 @@ private static PythonList ToList(IDictionary<object, object> self) {
7373
return ret;
7474
}
7575

76-
#if !IPY3
77-
public static PythonList items(IDictionary<object, object> self) => ToList();
78-
79-
public static IEnumerator iteritems(IDictionary<object, object> self) {
80-
return ((IEnumerable)items(self)).GetEnumerator();
81-
}
82-
83-
public static IEnumerator iterkeys(IDictionary<object, object> self) {
84-
return ((IEnumerable)keys(self)).GetEnumerator();
85-
}
86-
87-
public static PythonList keys(IDictionary<object, object> self) {
88-
return PythonOps.MakeListFromSequence(self.Keys);
89-
}
90-
#endif
91-
9276
public static object pop(PythonDictionary self, object key) {
9377
//??? perf won't match expected Python perf
9478
if (self.TryGetValueNoMissing(key, out object ret)) {

Src/IronPython/Runtime/Operations/ObjectOps.cs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -430,11 +430,7 @@ private static PythonTuple ReduceProtocol2(CodeContext/*!*/ context, object self
430430

431431
object dictIterator = null;
432432
if (self is PythonDictionary) {
433-
#if IPY3
434433
dictIterator = Modules.Builtin.iter(context, PythonOps.Invoke(context, self, nameof(PythonDictionary.items)));
435-
#else
436-
dictIterator = PythonOps.Invoke(context, self, nameof(PythonDictionary.iteritems));
437-
#endif
438434
}
439435

440436
return PythonTuple.MakeTuple(func, PythonTuple.MakeTuple(funcArgs), state, listIterator, dictIterator);

Src/IronPython/Runtime/PythonDictionary.cs

Lines changed: 1 addition & 113 deletions
Original file line numberDiff line numberDiff line change
@@ -316,13 +316,6 @@ public void clear() {
316316
_storage.Clear(ref _storage);
317317
}
318318

319-
#if !IPY3
320-
[Python3Warning("dict.has_key() not supported in 3.x; use the in operator")]
321-
public bool has_key(object key) {
322-
return DictionaryOps.has_key(this, key);
323-
}
324-
#endif
325-
326319
public object pop(object key) {
327320
return DictionaryOps.pop(this, key);
328321
}
@@ -343,51 +336,12 @@ public object setdefault(object key, object defaultValue) {
343336
return DictionaryOps.setdefault(this, key, defaultValue);
344337
}
345338

346-
#if IPY3
347339
public DictionaryItemView items() => new DictionaryItemView(this);
348340

349341
public DictionaryKeyView keys() => new DictionaryKeyView(this);
350342

351343
public DictionaryValueView values() => new DictionaryValueView(this);
352344

353-
#else
354-
public virtual PythonList keys() {
355-
PythonList res = new PythonList();
356-
foreach (KeyValuePair<object, object> kvp in _storage.GetItems()) {
357-
res.append(kvp.Key);
358-
}
359-
return res;
360-
}
361-
362-
public virtual PythonList values() {
363-
PythonList res = new PythonList();
364-
foreach (KeyValuePair<object, object> kvp in _storage.GetItems()) {
365-
res.append(kvp.Value);
366-
}
367-
return res;
368-
}
369-
370-
public virtual PythonList items() {
371-
PythonList res = new PythonList();
372-
foreach (KeyValuePair<object, object> kvp in _storage.GetItems()) {
373-
res.append(PythonTuple.MakeTuple(kvp.Key, kvp.Value));
374-
}
375-
return res;
376-
}
377-
378-
public IEnumerator iteritems() => new DictionaryItemEnumerator(_storage);
379-
380-
public IEnumerator iterkeys() => new DictionaryKeyEnumerator(_storage);
381-
382-
public IEnumerator itervalues() => new DictionaryValueEnumerator(_storage);
383-
384-
public IEnumerable viewitems() => new DictionaryItemView(this);
385-
386-
public IEnumerable viewkeys() => new DictionaryKeyView(this);
387-
388-
public IEnumerable viewvalues() => new DictionaryValueView(this);
389-
#endif
390-
391345
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1822:MarkMembersAsStatic")]
392346
public void update() {
393347
}
@@ -458,12 +412,7 @@ public static object fromkeys(CodeContext context, PythonType cls, object seq) {
458412

459413
[ClassMethod]
460414
public static object fromkeys(CodeContext context, PythonType cls, object seq, object value) {
461-
#if IPY3
462-
Range xr = seq as Range;
463-
#else
464-
XRange xr = seq as XRange;
465-
#endif
466-
if (xr != null) {
415+
if (seq is Range xr) {
467416
int n = xr.__len__();
468417
object ret = context.LanguageContext.CallSplat(cls);
469418
if (ret.GetType() == typeof(PythonDictionary)) {
@@ -514,45 +463,6 @@ public object __ne__(CodeContext/*!*/ context, object other) {
514463
);
515464
}
516465

517-
#if !IPY3
518-
[return: MaybeNotImplemented]
519-
public object __cmp__(CodeContext context, object other) {
520-
IDictionary<object, object> oth = other as IDictionary<object, object>;
521-
// CompareTo is allowed to throw (string, int, etc... all do it if they don't get a matching type)
522-
if (oth == null) {
523-
object len, iteritems;
524-
if (!PythonOps.TryGetBoundAttr(context, other, "__len__", out len) ||
525-
!PythonOps.TryGetBoundAttr(context, other, "iteritems", out iteritems)) {
526-
return NotImplementedType.Value;
527-
}
528-
529-
// user-defined dictionary...
530-
int lcnt = Count;
531-
int rcnt = context.LanguageContext.ConvertToInt32(PythonOps.CallWithContext(context, len));
532-
533-
if (lcnt != rcnt) return lcnt > rcnt ? 1 : -1;
534-
535-
return DictionaryOps.CompareToWorker(context, this, new PythonList(PythonOps.CallWithContext(context, iteritems)));
536-
}
537-
538-
CompareUtil.Push(this, oth);
539-
try {
540-
return DictionaryOps.CompareTo(context, this, oth);
541-
} finally {
542-
CompareUtil.Pop(this, oth);
543-
}
544-
}
545-
546-
public int __cmp__(CodeContext/*!*/ context, [NotNull]PythonDictionary/*!*/ other) {
547-
CompareUtil.Push(this, other);
548-
try {
549-
return DictionaryOps.CompareTo(context, this, other);
550-
} finally {
551-
CompareUtil.Pop(this, other);
552-
}
553-
}
554-
#endif
555-
556466
// these are present in CPython but always return NotImplemented.
557467
[return: MaybeNotImplemented]
558468
[Python3Warning("dict inequality comparisons not supported in 3.x")]
@@ -889,11 +799,7 @@ public override List<KeyValuePair<object, object>> GetItems() {
889799
/// innerEnum.MoveNext() will throw InvalidOperation even if the values get changed,
890800
/// which is supported in python
891801
/// </summary>
892-
#if IPY3
893802
[PythonType("dict_keyiterator")]
894-
#else
895-
[PythonType("dictionary-keyiterator")]
896-
#endif
897803
public sealed class DictionaryKeyEnumerator : IEnumerator<object> {
898804
private readonly int _size;
899805
private readonly DictionaryStorage _dict;
@@ -937,13 +843,11 @@ void IDisposable.Dispose() { }
937843

938844
#region Pickling
939845

940-
#if IPY3
941846
public object __reduce__(CodeContext context) {
942847
object iter;
943848
context.TryLookupBuiltin("iter", out iter);
944849
return PythonTuple.MakeTuple(iter, PythonTuple.MakeTuple(PythonList.FromArrayNoCopy(_dict.GetKeys().Skip(_pos + 1).ToArray())));
945850
}
946-
#endif
947851

948852
#endregion
949853
}
@@ -954,11 +858,7 @@ public object __reduce__(CodeContext context) {
954858
/// innerEnum.MoveNext() will throw InvalidOperation even if the values get changed,
955859
/// which is supported in python
956860
/// </summary>
957-
#if IPY3
958861
[PythonType("dict_valueiterator")]
959-
#else
960-
[PythonType("dictionary-valueiterator")]
961-
#endif
962862
public sealed class DictionaryValueEnumerator : IEnumerator<object> {
963863
private readonly int _size;
964864
private DictionaryStorage _dict;
@@ -1005,13 +905,11 @@ void IDisposable.Dispose() { }
1005905

1006906
#region Pickling
1007907

1008-
#if IPY3
1009908
public object __reduce__(CodeContext context) {
1010909
object iter;
1011910
context.TryLookupBuiltin("iter", out iter);
1012911
return PythonTuple.MakeTuple(iter, PythonTuple.MakeTuple(PythonList.FromArrayNoCopy(_dict.GetItems().Skip(_pos + 1).Select(x => x.Value).ToArray())));
1013912
}
1014-
#endif
1015913

1016914
#endregion
1017915
}
@@ -1022,11 +920,7 @@ public object __reduce__(CodeContext context) {
1022920
/// innerEnum.MoveNext() will throw InvalidOperation even if the values get changed,
1023921
/// which is supported in python
1024922
/// </summary>
1025-
#if IPY3
1026923
[PythonType("dict_itemiterator")]
1027-
#else
1028-
[PythonType("dictionary-itemiterator")]
1029-
#endif
1030924
public sealed class DictionaryItemEnumerator : IEnumerator<object> {
1031925
private readonly int _size;
1032926
private readonly DictionaryStorage _dict;
@@ -1075,13 +969,11 @@ void IDisposable.Dispose() { }
1075969

1076970
#region Pickling
1077971

1078-
#if IPY3
1079972
public object __reduce__(CodeContext context) {
1080973
object iter;
1081974
context.TryLookupBuiltin("iter", out iter);
1082975
return PythonTuple.MakeTuple(iter, PythonTuple.MakeTuple(PythonList.FromArrayNoCopy(_dict.GetItems().Skip(_pos + 1).Select(x => x.Value).ToArray())));
1083976
}
1084-
#endif
1085977

1086978
#endregion
1087979
}
@@ -1541,14 +1433,12 @@ public string __repr__(CodeContext context) {
15411433

15421434
#endregion
15431435

1544-
#if IPY3
15451436
public bool isdisjoint(IEnumerable other) {
15461437
return SetStorage.Intersection(
15471438
SetStorage.GetItemsWorker(GetEnumerator()),
15481439
SetStorage.GetItems(other)
15491440
).Count == 0;
15501441
}
1551-
#endif
15521442

15531443
public override int GetHashCode() {
15541444
return base.GetHashCode();
@@ -1903,14 +1793,12 @@ public string __repr__(CodeContext context) {
19031793

19041794
#endregion
19051795

1906-
#if IPY3
19071796
public bool isdisjoint(IEnumerable other) {
19081797
return SetStorage.Intersection(
19091798
SetStorage.GetItemsWorker(GetEnumerator()),
19101799
SetStorage.GetItems(other)
19111800
).Count == 0;
19121801
}
1913-
#endif
19141802

19151803
public override int GetHashCode() {
19161804
return base.GetHashCode();

0 commit comments

Comments
 (0)