-
Notifications
You must be signed in to change notification settings - Fork 105
Expand file tree
/
Copy pathproperty.go
More file actions
48 lines (39 loc) · 1.19 KB
/
property.go
File metadata and controls
48 lines (39 loc) · 1.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
// Copyright 2018 The go-python Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// Property object
package py
// A python Property object
type Property struct {
Fget func(self Object) (Object, error)
Fset func(self, value Object) error
Fdel func(self Object) error
Doc string
}
var PropertyType = NewType("property", "property object")
// Type of this object
func (o *Property) Type() *Type {
return PropertyType
}
func (p *Property) M__get__(instance, owner Object) (Object, error) {
if p.Fget == nil {
return nil, ExceptionNewf(AttributeError, "can't get attribute")
}
return p.Fget(instance)
}
func (p *Property) M__set__(instance, value Object) (Object, error) {
if p.Fset == nil {
return nil, ExceptionNewf(AttributeError, "can't set attribute")
}
return None, p.Fset(instance, value)
}
func (p *Property) M__delete__(instance Object) (Object, error) {
if p.Fdel == nil {
return nil, ExceptionNewf(AttributeError, "can't delete attribute")
}
return None, p.Fdel(instance)
}
// Interfaces
var _ I__get__ = (*Property)(nil)
var _ I__set__ = (*Property)(nil)
var _ I__delete__ = (*Property)(nil)