Skip to content

Commit

Permalink
feat: impl Eq, Hash, Ord for Python module types
Browse files Browse the repository at this point in the history
  • Loading branch information
mtshiba committed Mar 5, 2024
1 parent 1691647 commit c94ac76
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 0 deletions.
18 changes: 18 additions & 0 deletions crates/erg_compiler/lib/pystd/datetime.d.er
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ time = pyimport "time"
.MAXYEAR: {9999}

.TimeDelta = 'timedelta': ClassType
.TimeDelta <: Eq
.TimeDelta <: Hash
.TimeDelta <: Ord
.TimeDelta.
__call__: (days := Nat, seconds := Nat, microseconds := Nat, milliseconds := Nat, minutes := Nat, hours := Nat, weeks := Nat) -> .TimeDelta
__eq__: (self: .TimeDelta, other: .TimeDelta) -> Bool
Expand All @@ -17,6 +20,9 @@ time = pyimport "time"
resolution: .TimeDelta
total_seconds: (self: .TimeDelta) -> Float
.Date = 'date': ClassType
.Date <: Eq
.Date <: Hash
.Date <: Ord
.Date.
__call__: (year: Nat, month: Nat, day: Nat) -> .Date
__eq__: (self: .Date, other: .Date) -> Bool
Expand Down Expand Up @@ -45,7 +51,13 @@ time = pyimport "time"
max: .Date
resolution: .TimeDelta
.TZInfo = 'tzinfo': ClassType
.TZInfo <: Eq
.TZInfo <: Hash
.TZInfo <: Ord
.Time = 'time': ClassType
.Time <: Eq
.Time <: Hash
.Time <: Ord
.Time.
__call__: (hour: 0..23, minute: 0..59, second := 0..59, microsecond := Nat, tzinfo := .TZInfo or NoneType) -> .Time
__eq__: (self: .Time, other: .Time) -> Bool
Expand All @@ -61,6 +73,9 @@ time = pyimport "time"
replace: (self: .Time, hour := 0..23, minute := 0..59, second := 0..59, microsecond := Nat, tzinfo := .TZInfo or NoneType) -> .Time
isoformat: (self: .Time, timespec := Str) -> Str
.DateTime = 'datetime': ClassType
.DateTime <: Eq
.DateTime <: Hash
.DateTime <: Ord
.DateTime.
__call__: (year: 0..9999, month: 1..12, day: 1..31, hour := 0..23, minute := 0..59, second := 0..59, microsecond := Nat, tzinfo := .TZInfo or NoneType) -> .DateTime
__eq__: (self: .DateTime, other: .DateTime) -> Bool
Expand All @@ -87,6 +102,9 @@ time = pyimport "time"
replace: (self: .DateTime, year := 0..9999, month := 1..12, day := 1..31, hour := 0..23, minute := 0..59, second := 0..59, microsecond := Nat, tzinfo := .TZInfo or NoneType) -> .DateTime
utcoffset: (self: .DateTime) -> .TimeDelta or NoneType
.TimeZone = 'timezone': ClassType
.TimeZone <: Eq
.TimeZone <: Hash
.TimeZone <: Ord
.TimeZone.
__eq__: (self: .TimeZone, other: .TimeZone) -> Bool
__ne__: (self: .TimeZone, other: .TimeZone) -> Bool
Expand Down
3 changes: 3 additions & 0 deletions crates/erg_compiler/lib/pystd/decimal.d.er
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,9 @@
.setcontext!: (ctx: .Context!) => NoneType
.localcontext: (ctx := .Context!) -> .Context!

.Decimal <: Eq
.Decimal <: Hash
.Decimal <: Ord
.Decimal.
__call__: (value := Str or Float) -> .Decimal
adjusted: (self: .Decimal) -> Int
Expand Down
3 changes: 3 additions & 0 deletions crates/erg_compiler/lib/pystd/fractions.d.er
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
decimal = pyimport "decimal"

.Fraction: ClassType
.Fraction <: Eq
.Fraction <: Hash
.Fraction <: Ord
.Fraction.
numerator: Int
denominator: Int
Expand Down
2 changes: 2 additions & 0 deletions crates/erg_compiler/lib/pystd/pathlib.d.er
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
.PurePath: ClassType
.PurePath <: PathLike
.PurePath <: Eq
.PurePath <: Hash
.PurePath.
parts: [Str; _]
drive: Str
Expand Down

0 comments on commit c94ac76

Please sign in to comment.