Skip to content

Commit 655e6b5

Browse files
authored
Rename Range to PythonRange (#708)
* Rename Range to PythonRange * Fix failing test
1 parent 2ba462f commit 655e6b5

4 files changed

Lines changed: 37 additions & 52 deletions

File tree

Src/IronPython/Modules/Builtin.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1360,7 +1360,7 @@ public static PythonType property {
13601360

13611361
public static PythonType range {
13621362
get {
1363-
return DynamicHelpers.GetPythonTypeFromType(typeof(Runtime.Range));
1363+
return DynamicHelpers.GetPythonTypeFromType(typeof(Runtime.PythonRange));
13641364
}
13651365
}
13661366

Src/IronPython/Runtime/PythonDictionary.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -412,7 +412,7 @@ public static object fromkeys(CodeContext context, PythonType cls, object seq) {
412412

413413
[ClassMethod]
414414
public static object fromkeys(CodeContext context, PythonType cls, object seq, object value) {
415-
if (seq is Range xr) {
415+
if (seq is PythonRange xr) {
416416
int n = xr.__len__();
417417
object ret = context.LanguageContext.CallSplat(cls);
418418
if (ret.GetType() == typeof(PythonDictionary)) {
Lines changed: 34 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,13 @@ namespace IronPython.Runtime {
2121
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1710:IdentifiersShouldHaveCorrectSuffix")]
2222
[PythonType("range")]
2323
[DontMapIEnumerableToContains]
24-
public sealed class Range : IEnumerable<int>, ICodeFormattable, IList, IReversible {
24+
public sealed class PythonRange : IEnumerable<int>, ICodeFormattable, IList, IReversible {
2525
private int _length;
2626

27-
public Range(object stop) : this(0, stop, 1) { }
28-
public Range(object start, object stop) : this(start, stop, 1) { }
27+
public PythonRange(object stop) : this(0, stop, 1) { }
28+
public PythonRange(object start, object stop) : this(start, stop, 1) { }
2929

30-
public Range(object start, object stop, object step) {
30+
public PythonRange(object start, object stop, object step) {
3131
Initialize(start, stop, step);
3232
}
3333

@@ -104,11 +104,11 @@ public object this[[NotNull]Slice slice] {
104104
get {
105105
int ostart, ostop, ostep;
106106
slice.indices(_length, out ostart, out ostop, out ostep);
107-
return new Range(Compute(ostart), Compute(ostop), step * ostep);
107+
return new PythonRange(Compute(ostart), Compute(ostop), step * ostep);
108108
}
109109
}
110110

111-
public bool __eq__(Range other) {
111+
public bool __eq__(PythonRange other) {
112112
if (_length != other._length) {
113113
return false;
114114
}
@@ -127,7 +127,7 @@ public bool __eq__(Range other) {
127127
return step == other.step;
128128
}
129129

130-
public bool __ne__(Range other) {
130+
public bool __ne__(PythonRange other) {
131131
return !__eq__(other);
132132
}
133133

@@ -143,19 +143,19 @@ public int __hash__() {
143143
return hash;
144144
}
145145

146-
public bool __lt__(Range other) {
146+
public bool __lt__(PythonRange other) {
147147
throw new TypeErrorException("unorderable types: range() < range()");
148148
}
149149

150-
public bool __le__(Range other) {
150+
public bool __le__(PythonRange other) {
151151
throw new TypeErrorException("unorderable types: range() <= range()");
152152
}
153153

154-
public bool __gt__(Range other) {
154+
public bool __gt__(PythonRange other) {
155155
throw new TypeErrorException("unorderable types: range() > range()");
156156
}
157157

158-
public bool __ge__(Range other) {
158+
public bool __ge__(PythonRange other) {
159159
throw new TypeErrorException("unorderable types: range() >= range()");
160160
}
161161

@@ -250,17 +250,17 @@ private int Last() {
250250
}
251251

252252
public IEnumerator __reversed__() {
253-
return new RangeIterator(new Range(Last(), start - step, -step));
253+
return new PythonRangeIterator(new PythonRange(Last(), start - step, -step));
254254
}
255255

256256
IEnumerator IEnumerable.GetEnumerator() {
257-
return new RangeIterator(this);
257+
return new PythonRangeIterator(this);
258258
}
259259

260260
#region IEnumerable<int> Members
261261

262262
IEnumerator<int> IEnumerable<int>.GetEnumerator() {
263-
return new RangeIterator(this);
263+
return new PythonRangeIterator(this);
264264
}
265265

266266
#endregion
@@ -276,35 +276,26 @@ IEnumerator<int> IEnumerable<int>.GetEnumerator() {
276276
#endregion
277277

278278
#region ICollection Members
279+
279280
void ICollection.CopyTo(Array array, int index) {
280281
foreach (object o in this) {
281282
array.SetValue(o, index++);
282283
}
283284
}
284285

285-
int ICollection.Count {
286-
get { return _length; }
287-
}
286+
int ICollection.Count => _length;
288287

289-
bool ICollection.IsSynchronized {
290-
get { return false; }
291-
}
288+
bool ICollection.IsSynchronized => false;
292289

293-
object ICollection.SyncRoot {
294-
get { return null; }
295-
}
290+
object ICollection.SyncRoot => null;
296291

297292
#endregion
298293

299294
#region IList Members
300295

301-
int IList.Add(object value) {
302-
throw new InvalidOperationException();
303-
}
296+
int IList.Add(object value) => throw new InvalidOperationException();
304297

305-
void IList.Clear() {
306-
throw new InvalidOperationException();
307-
}
298+
void IList.Clear() => throw new InvalidOperationException();
308299

309300
bool IList.Contains(object value) {
310301
return ((IList)this).IndexOf(value) != -1;
@@ -322,25 +313,15 @@ int IList.IndexOf(object value) {
322313
return -1;
323314
}
324315

325-
void IList.Insert(int index, object value) {
326-
throw new InvalidOperationException();
327-
}
316+
void IList.Insert(int index, object value) => throw new InvalidOperationException();
328317

329-
bool IList.IsFixedSize {
330-
get { return true; }
331-
}
318+
bool IList.IsFixedSize => true;
332319

333-
bool IList.IsReadOnly {
334-
get { return true; }
335-
}
320+
bool IList.IsReadOnly => true;
336321

337-
void IList.Remove(object value) {
338-
throw new InvalidOperationException();
339-
}
322+
void IList.Remove(object value) => throw new InvalidOperationException();
340323

341-
void IList.RemoveAt(int index) {
342-
throw new InvalidOperationException();
343-
}
324+
void IList.RemoveAt(int index) => throw new InvalidOperationException();
344325

345326
object IList.this[int index] {
346327
get {
@@ -364,22 +345,24 @@ object IList.this[int index] {
364345
}
365346

366347
[PythonType("range_iterator")]
367-
public sealed class RangeIterator : IEnumerable, IEnumerator<int> {
368-
private readonly Range _range;
348+
public sealed class PythonRangeIterator : IEnumerable, IEnumerator<int> {
349+
private readonly PythonRange _range;
369350
private int _value;
370351
private int _position;
371352

372-
public RangeIterator(Range range) {
353+
internal PythonRangeIterator(PythonRange range) {
373354
_range = range;
374355
_value = range.start - range.step; // this could cause overflow, fine
375356
}
376357

358+
[PythonHidden]
377359
public object Current {
378360
get {
379361
return ScriptingRuntimeHelpers.Int32ToObject(_value);
380362
}
381363
}
382364

365+
[PythonHidden]
383366
public bool MoveNext() {
384367
if (_position >= _range.__len__()) {
385368
return false;
@@ -390,6 +373,7 @@ public bool MoveNext() {
390373
return true;
391374
}
392375

376+
[PythonHidden]
393377
public void Reset() {
394378
_value = _range.start - _range.step;
395379
_position = 0;
@@ -422,13 +406,14 @@ int IEnumerator<int>.Current {
422406

423407
#region IDisposable Members
424408

425-
public void Dispose() {
426-
}
409+
[PythonHidden]
410+
public void Dispose() { }
427411

428412
#endregion
429413

430414
#region IEnumerable Members
431415

416+
[PythonHidden]
432417
public IEnumerator GetEnumerator() {
433418
return this;
434419
}

Tests/interop/net/dynamic/test_dynamic_regressions.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ def setUp(self):
8585
def test_cp24117(self):
8686
import IronPythonTest.DynamicRegressions as DR
8787
self.assertEqual(DR.cp24117(range), "IronPython.Runtime.Types.PythonType")
88-
self.assertEqual(DR.cp24117(range(3)), "IronPython.Runtime.Range")
88+
self.assertEqual(DR.cp24117(range(3)), "IronPython.Runtime.PythonRange")
8989

9090
def test_cp24118(self):
9191
import IronPythonTest.DynamicRegressions as DR

0 commit comments

Comments
 (0)