CadQuery / CadQuery/cadquery

UnboundLocalError if Vector supplied with incorrect-length tuple/list

Open
#981 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Python
Stars
5.8k
Forks
541
Avg merge
3d 2h
Merged PRs (30d)
5

Description

When creating a `cadquery.Vector` instance, if it is passed a tuple or list with a length that is not 2 or 3, it will crash with an unbound local error rather than throwing a TypeError as would happen for other issues.

```python
>>> import cadquery as cq
>>> cq.Vector((1, 2, 3, 4)) # Actual behaviour
Traceback (most recent call last):
File "", line 1, in
File "/home/jake/.conda/envs/cadquery/lib/python3.7/site-packages/cadquery/occ_impl/geom.py", line 93, in __init__
self._wrapped = fV
UnboundLocalError: local variable 'fV' referenced before assignment
>>> cq.Vector(1, 2, 3, 4) # Expected behaviour
Traceback (most recent call last):
File "", line 1, in
File "/home/jake/.conda/envs/cadquery/lib/python3.7/site-packages/cadquery/occ_impl/geom.py", line 91, in __init__
raise TypeError("Expected three floats, OCC gp_, or 3-tuple")
TypeError: Expected three floats, OCC gp_, or 3-tuple
```

CadQuery version: `master` as of now.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.