Compare commits
11 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 8352bb5c9a | |||
| fc34b876fd | |||
| 183993cfc5 | |||
| 9be3b4b93d | |||
| 0b14660115 | |||
| 68c4c682a0 | |||
| 4f93ddcaf3 | |||
| e842f651b9 | |||
| 7e1bec1aba | |||
| 1fb9a4f5fe | |||
| 1668c80bed |
@@ -289,6 +289,17 @@ def _validate_type(t: Optional[type], value: Any) -> Tuple[bool, Any]:
|
||||
values.append(item_value)
|
||||
return True, tuple(values)
|
||||
|
||||
if origin is set:
|
||||
if not isinstance(value, set):
|
||||
return False, value
|
||||
if not hasattr(t, "__args__"):
|
||||
return True, value
|
||||
t_items = t.__args__[0] # type: ignore
|
||||
first_item_valid, _ = _validate_type(t_items, next(iter(value)))
|
||||
if first_item_valid:
|
||||
return True, value
|
||||
return False, value
|
||||
|
||||
if isinstance(value, t):
|
||||
return True, value
|
||||
|
||||
|
||||
@@ -6,7 +6,10 @@ from specklepy.objects.structural.analysis import (
|
||||
ModelSettings,
|
||||
ModelUnits,
|
||||
)
|
||||
from specklepy.objects.structural.axis import Axis
|
||||
from specklepy.objects.structural.axis import (
|
||||
AxisType,
|
||||
Axis
|
||||
)
|
||||
from specklepy.objects.structural.geometry import (
|
||||
Element1D,
|
||||
Element2D,
|
||||
@@ -82,6 +85,7 @@ __all__ = [
|
||||
"ElementType1D",
|
||||
"ElementType2D",
|
||||
"ElementType3D",
|
||||
"AxisType",
|
||||
"Axis",
|
||||
"Node",
|
||||
"Restraint",
|
||||
|
||||
@@ -1,10 +1,17 @@
|
||||
from typing import Optional
|
||||
from enum import Enum
|
||||
|
||||
from specklepy.objects.base import Base
|
||||
from specklepy.objects.geometry import Plane
|
||||
|
||||
|
||||
class AxisType(int, Enum):
|
||||
Cartesian = 0
|
||||
Cylindrical = 1
|
||||
Spherical = 2
|
||||
|
||||
|
||||
class Axis(Base, speckle_type="Objects.Structural.Geometry.Axis"):
|
||||
name: Optional[str] = None
|
||||
axisType: Optional[str] = None
|
||||
axisType: Optional[AxisType] = None
|
||||
plane: Optional[Plane] = None
|
||||
|
||||
@@ -5,7 +5,7 @@ from specklepy.objects.base import Base
|
||||
from specklepy.objects.structural.axis import Axis
|
||||
from specklepy.objects.structural.materials import StructuralMaterial
|
||||
|
||||
STRUCTURAL_PROPERTY = "Objectives.Structural.Properties"
|
||||
STRUCTURAL_PROPERTY = "Objects.Structural.Properties"
|
||||
|
||||
|
||||
class MemberType(int, Enum):
|
||||
@@ -90,7 +90,7 @@ class Property(Base, speckle_type=STRUCTURAL_PROPERTY):
|
||||
name: Optional[str] = None
|
||||
|
||||
|
||||
class SectionProfile(Base, speckle_type=STRUCTURAL_PROPERTY + ".SectionProfile"):
|
||||
class SectionProfile(Base, speckle_type=STRUCTURAL_PROPERTY + ".Profiles.SectionProfile"):
|
||||
name: Optional[str] = None
|
||||
shapeType: Optional[ShapeType] = None
|
||||
area: float = 0.0
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
from enum import Enum, IntEnum
|
||||
from typing import Any, Dict, List, Optional, Tuple, Union
|
||||
from typing import Any, Dict, List, Optional, Set, Tuple, Union
|
||||
|
||||
import pytest
|
||||
|
||||
@@ -88,6 +88,14 @@ fake_bases = [FakeBase("foo"), FakeBase("bar")]
|
||||
# given our current rules, this is the reality. Its just sad...
|
||||
(Tuple[str, str, str], (1, "foo", "bar"), True, ("1", "foo", "bar")),
|
||||
(Tuple[str, Optional[str], str], (1, None, "bar"), True, ("1", None, "bar")),
|
||||
(Set[bool], set([1, 2]), False, set([1, 2])),
|
||||
(Set[int], set([1, 2]), True, set([1, 2])),
|
||||
(Set[int], set([None, 2]), True, set([None, 2])),
|
||||
# not testing this, since order of input iterables in sets are not preserved
|
||||
# easily produces false reports since we're only checking the type of the
|
||||
# first item
|
||||
# (Set[int], set(["None", 2]), False, set(["None", 2])),
|
||||
(Set[Optional[int]], set([None, 2]), True, set([None, 2])),
|
||||
(Optional[Union[List[int], List[FakeBase]]], None, True, None),
|
||||
(Optional[Union[List[int], List[FakeBase]]], "foo", False, "foo"),
|
||||
(Union[List[int], List[FakeBase], None], "foo", False, "foo"),
|
||||
|
||||
Reference in New Issue
Block a user