Skip to content

Commit 40a2528

Browse files
committed
py: make == and != complain if comparing the same type with no __eq__ method
1 parent f148ad3 commit 40a2528

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

py/arithmetic.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -863,7 +863,11 @@ func Eq(a Object, b Object) (Object, error) {
863863
}
864864
}
865865

866-
return False, nil
866+
if a.Type() != b.Type() {
867+
return False, nil
868+
}
869+
870+
return nil, ExceptionNewf(TypeError, "unsupported operand type(s) for ==: '%s' and '%s'", a.Type().Name, b.Type().Name)
867871
}
868872

869873
// Ne two python objects returning a boolean result
@@ -892,5 +896,9 @@ func Ne(a Object, b Object) (Object, error) {
892896
}
893897
}
894898

895-
return True, nil
899+
if a.Type() != b.Type() {
900+
return True, nil
901+
}
902+
903+
return nil, ExceptionNewf(TypeError, "unsupported operand type(s) for !=: '%s' and '%s'", a.Type().Name, b.Type().Name)
896904
}

py/gen.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,12 @@ func {{.Title}}(a Object, b Object) (Object, error) {
194194
}
195195
}
196196
197-
return {{ if .FailReturn}}{{ .FailReturn }}, nil{{ else }}nil, ExceptionNewf(TypeError, "unsupported operand type(s) for {{.Operator}}: '%s' and '%s'", a.Type().Name, b.Type().Name){{ end }}
197+
{{ if .FailReturn}}
198+
if a.Type() != b.Type() {
199+
return {{ .FailReturn }}, nil
200+
}
201+
{{ end }}
202+
return nil, ExceptionNewf(TypeError, "unsupported operand type(s) for {{.Operator}}: '%s' and '%s'", a.Type().Name, b.Type().Name)
198203
}
199204
{{ end }}
200205
`

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy