MCPcopy Create free account
hub / github.com/PageBot/PageBot / isUnits

Function isUnits

Lib/pagebot/toolbox/units.py:264–291  ·  view source on GitHub ↗

Answers if u (and all of the other items in the argument list) are a Unit instance. >>> isUnits(Em(2)) True >>> isUnits(2) False >>> isUnits(pt(1), pt(2), pt(3)) True >>> isUnits(pt(1), pt(2), 3, pt(4)) False

(u, *args)

Source from the content-addressed store, hash-verified

262 return uu
263
264def isUnits(u, *args):
265 """Answers if u (and all of the other items in the argument list) are a
266 Unit instance.
267
268 >>> isUnits(Em(2))
269 True
270 >>> isUnits(2)
271 False
272 >>> isUnits(pt(1), pt(2), pt(3))
273 True
274 >>> isUnits(pt(1), pt(2), 3, pt(4))
275 False
276 """
277 if args:
278 if isinstance(u, (list, tuple)):
279 u = list(u)
280 else:
281 u = [u]
282 for arg in args:
283 u.append(arg)
284 if isUnit(u):
285 return True
286 if isinstance(u, (list, tuple)):
287 for uu in u:
288 if not isUnits(uu): # Can be nested tuples.
289 return False
290 return True
291 return False
292
293def isUnit(u):
294 """Answers if u is an instance of Unit.

Callers

nothing calls this directly

Calls 2

isUnitFunction · 0.85
appendMethod · 0.45

Tested by

no test coverage detected