Improve Inheriting Workplane Fluent Methods (#677)
* Return Instances of the Type of self from Fluent Methods * Updated `Workplane.workplane()`, `Workplane.copyWorkplane()`, `Workplane.newObject()` to return instances of a type that's based on the input parameters (such as `self`). * Updated type hints to reflect that return types of fluent methods depend on the type of method arguments. * Added a unit test to verify fluent methods in a derived class return instances of the derived class. * Fix Workpane MyPy Errors * Fixed type hints in `sweep()` and `_selectObjects()`. * Fix `test_cadquery.py` Formatting * Ran `black` on `test_cadquery.py`. * Renamed `TypeVar` `WorkplaneT` to `T` * Renamed `WorkplaneT` to `T` in `cq.py`. * Reformat with Black * Re-formatted `cq.py` with `black`. * Re-format with the Right Version of Black (19.10b0) * Re-formatted `cq.py` with `black` 19.10b0.
This commit is contained in:
352
cadquery/cq.py
352
cadquery/cq.py
File diff suppressed because it is too large
Load Diff
@ -225,6 +225,27 @@ class TestCadQuery(BaseTest):
|
|||||||
self.assertEqual(26, s.faces().size())
|
self.assertEqual(26, s.faces().size())
|
||||||
self.saveModel(s)
|
self.saveModel(s)
|
||||||
|
|
||||||
|
def testFluentMethodInheritance(self):
|
||||||
|
"""
|
||||||
|
Tests that a derived class inherits fluent methods which return
|
||||||
|
instances of derived class when inherited.
|
||||||
|
"""
|
||||||
|
|
||||||
|
class ExtendedWorkplane(Workplane):
|
||||||
|
def nonExistentInWorkplane(self):
|
||||||
|
pass
|
||||||
|
|
||||||
|
# Call an inherited fluent method:
|
||||||
|
wp = ExtendedWorkplane("XY").moveTo(1, 2)
|
||||||
|
|
||||||
|
# Verify that the inherited method returned an instance of the derived
|
||||||
|
# class:
|
||||||
|
self.assertEqual(type(wp), ExtendedWorkplane)
|
||||||
|
|
||||||
|
# The following is redundant, but can make the use case clearer.
|
||||||
|
# This must not raise an AttributeError:
|
||||||
|
wp.nonExistentInWorkplane()
|
||||||
|
|
||||||
def testPointList(self):
|
def testPointList(self):
|
||||||
"""
|
"""
|
||||||
Tests adding points and using them
|
Tests adding points and using them
|
||||||
|
Reference in New Issue
Block a user