Skip to content

Commit 012352a

Browse files
committed
Clean up nt.uname_result
1 parent bcc8fc4 commit 012352a

1 file changed

Lines changed: 23 additions & 13 deletions

File tree

  • Src/IronPython.Modules

Src/IronPython.Modules/nt.cs

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -736,24 +736,34 @@ public static void symlink(CodeContext context, [NotNone] Bytes src, [NotNone] B
736736
public static void symlink(CodeContext context, object? src, object? dst, [ParamDictionary, NotNone] IDictionary<string, object> kwargs, [NotNone] params object[] args)
737737
=> symlink(ConvertToFsString(context, src, nameof(src)), ConvertToFsString(context, dst, nameof(dst)), kwargs, args);
738738

739-
public class uname_result : PythonTuple {
740-
// TODO: posix: support constructor with a sequence, see construction of stat_result
741-
public uname_result(string? sysname, string? nodename, string? release, string? version, string? machine) :
742-
base(new object?[] { sysname, nodename, release, version, machine }) { }
743-
744-
public string? sysname => (string?)this[0];
739+
[PythonType]
740+
public sealed class uname_result : PythonTuple {
741+
public const int n_fields = 5;
742+
public const int n_sequence_fields = 5;
743+
public const int n_unnamed_fields = 0;
745744

746-
public string? nodename => (string?)this[1];
745+
internal uname_result(object?[] sequence) : base(sequence) {
746+
if (_data.Length != n_sequence_fields) {
747+
// TODO: CPython shows nt/posix instead of os...
748+
throw PythonOps.ValueError($"os.{nameof(uname_result)}() takes a 5-sequence ({_data.Length}-sequence given)");
749+
}
750+
}
747751

748-
public string? release => (string?)this[2];
752+
internal uname_result(string? sysname, string? nodename, string? release, string? version, string? machine) :
753+
base(new object?[] { sysname, nodename, release, version, machine }) { }
749754

750-
public string? version => (string?)this[3];
755+
public static uname_result __new__(CodeContext context, [NotNone] PythonType cls, [NotNone] IEnumerable<object?> sequence) {
756+
return new uname_result(sequence.ToArray());
757+
}
751758

752-
public string? machine => (string?)this[4];
759+
public object? sysname => this[0];
760+
public object? nodename => this[1];
761+
public object? release => this[2];
762+
public object? version => this[3];
763+
public object? machine => this[4];
753764

754-
public override string ToString() {
755-
// TODO: posix: handle null values, see terminal_size.__repr__()
756-
return $"posix.uname_result(sysname='{sysname}', nodename='{nodename}', release='{release}', version='{version}', machine='{machine}')";
765+
public override string __repr__(CodeContext context) {
766+
return $"os.{nameof(uname_result)}sysname={PythonOps.Repr(context, sysname)}, nodename={PythonOps.Repr(context, nodename)}, release={PythonOps.Repr(context, release)}, version={PythonOps.Repr(context, version)}, machine={PythonOps.Repr(context, machine)})";
757767
}
758768
}
759769

0 commit comments

Comments
 (0)