Preventing overriding of getters by is_.. predicates

This commit is contained in:
Matthias Koefferlein 2022-10-24 21:06:03 +02:00
parent c8d86f8e73
commit 2b60e2f6e9
2 changed files with 46 additions and 23 deletions

View File

@ -167,13 +167,6 @@ MethodTable::MethodTable (const gsi::ClassBase *cls_decl, PythonModule *module)
// static methods without arguments which start with a capital letter are treated as constants
add_getter (syn->name, *m);
} else {
if (syn->is_predicate && std::string (syn->name, 0, 3) == "is_") {
std::string n = std::string (syn->name, 3, std::string::npos);
if (is_property_setter (st, n) && ! is_property_getter (st, n)) {
// synthesize a getter from is_...? predicates (e.g. is_empty? -> empty getter)
add_getter (n, *m);
}
}
add_method (syn->name, *m);
}
}
@ -181,6 +174,27 @@ MethodTable::MethodTable (const gsi::ClassBase *cls_decl, PythonModule *module)
}
}
// synthesize a getter from is_...? predicates (e.g. is_empty? -> empty getter)
for (gsi::ClassBase::method_iterator m = cls_decl->begin_methods (); m != cls_decl->end_methods (); ++m) {
if (! (*m)->is_callback () && ! (*m)->is_signal ()) {
bool st = (*m)->is_static ();
bool no_args = ((*m)->end_arguments () == (*m)->begin_arguments ());
for (gsi::MethodBase::synonym_iterator syn = (*m)->begin_synonyms (); syn != (*m)->end_synonyms (); ++syn) {
if (no_args && ! syn->is_getter && ! syn->is_setter && syn->is_predicate && std::string (syn->name, 0, 3) == "is_") {
std::string n = std::string (syn->name, 3, std::string::npos);
if (is_property_setter (st, n) && ! is_property_getter (st, n)) {
add_getter (n, *m);
}
}
}
}
}
}
size_t

View File

@ -27898,11 +27898,12 @@ class Shape:
TUserObject: ClassVar[int]
r"""
"""
box: bool
box: Any
r"""
Getter:
@brief Returns true if the shape is a box
@brief Gets the box object
Starting with version 0.23, this method returns nil, if the shape does not represent a box.
Setter:
@brief Replaces the shape by the given box (in micrometer units)
This method replaces the shape by the given box, like \box= with a \Box argument does. This version translates the box from micrometer units to database units internally.
@ -28194,21 +28195,22 @@ class Shape:
This method has been introduced in version 0.25.
"""
edge: bool
edge: Any
r"""
Getter:
@brief Returns true, if the object is an edge
@brief Returns the edge object
Starting with version 0.23, this method returns nil, if the shape does not represent an edge.
Setter:
@brief Replaces the shape by the given edge (in micrometer units)
This method replaces the shape by the given edge, like \edge= with a \Edge argument does. This version translates the edge from micrometer units to database units internally.
This method has been introduced in version 0.25.
"""
edge_pair: bool
edge_pair: Any
r"""
Getter:
@brief Returns true, if the object is an edge pair
@brief Returns the edge pair object
This method has been introduced in version 0.26.
Setter:
@ -28244,11 +28246,12 @@ class Shape:
This method has been added in version 0.23.
"""
path: bool
path: Any
r"""
Getter:
@brief Returns true, if the shape is a path
@brief Returns the path object
Starting with version 0.23, this method returns nil, if the shape does not represent a path.
Setter:
@brief Replaces the shape by the given path object
This method replaces the shape by the given path object. This method can only be called for editable layouts. It does not change the user properties of the shape.
@ -28338,12 +28341,15 @@ class Shape:
This method has been introduced in version 0.23.
"""
polygon: bool
polygon: Any
r"""
Getter:
@brief Returns true, if the shape is a polygon
@brief Returns the polygon object
Returns the polygon object that this shape refers to or converts the object to a polygon. Paths, boxes and simple polygons are converted to polygons. For paths this operation renders the path's hull contour.
Starting with version 0.23, this method returns nil, if the shape does not represent a geometrical primitive that can be converted to a polygon.
This method returns true only if the object is a polygon or a simple polygon. Other objects can convert to polygons, for example paths, so it may be possible to use the \polygon method also if is_polygon? does not return true.
Setter:
@brief Replaces the shape by the given polygon object
This method replaces the shape by the given polygon object. This method can only be called for editable layouts. It does not change the user properties of the shape.
@ -28379,12 +28385,14 @@ class Shape:
This method has been introduced in version 0.23.
"""
simple_polygon: bool
simple_polygon: Any
r"""
Getter:
@brief Returns true, if the shape is a simple polygon
@brief Returns the simple polygon object
Returns the simple polygon object that this shape refers to or converts the object to a simple polygon. Paths, boxes and polygons are converted to simple polygons. Polygons with holes will have their holes removed but introducing cut lines that connect the hole contours with the outer contour.
Starting with version 0.23, this method returns nil, if the shape does not represent a geometrical primitive that can be converted to a simple polygon.
This method returns true only if the object is a simple polygon. The simple polygon identity is contained in the polygon identity, so usually it is sufficient to use \is_polygon? and \polygon instead of specifically handle simply polygons. This method is provided only for specific optimisation purposes.
Setter:
@brief Replaces the shape by the given simple polygon object
This method replaces the shape by the given simple polygon object. This method can only be called for editable layouts. It does not change the user properties of the shape.
@ -28392,11 +28400,12 @@ class Shape:
This method has been introduced in version 0.22.
"""
text: bool
text: Any
r"""
Getter:
@brief Returns true, if the object is a text
@brief Returns the text object
Starting with version 0.23, this method returns nil, if the shape does not represent a text.
Setter:
@brief Replaces the shape by the given text object
This method replaces the shape by the given text object. This method can only be called for editable layouts. It does not change the user properties of the shape.