|
1 | | -from __future__ import absolute_import |
2 | | -from __future__ import division |
3 | | -from __future__ import print_function |
4 | | - |
5 | | -try: |
6 | | - from typing import TypeVar # noqa: F401 |
7 | | - |
8 | | - D = TypeVar("D", bound="Data") |
9 | | -except ImportError: |
10 | | - pass |
11 | | - |
12 | 1 | import hashlib |
13 | 2 | from copy import deepcopy |
| 3 | +from typing import TypeVar |
14 | 4 | from uuid import UUID |
15 | 5 | from uuid import uuid4 |
16 | 6 |
|
17 | 7 | import compas |
18 | 8 |
|
19 | | -# ============================================================================== |
20 | | -# If you ever feel tempted to use ABCMeta in your code: don't, just DON'T. |
21 | | -# Assigning __metaclass__ = ABCMeta to a class causes a severe memory leak/performance |
22 | | -# degradation on IronPython 2.7. |
23 | | - |
24 | | -# See these issues for more details: |
25 | | -# - https://github.com/compas-dev/compas/issues/562 |
26 | | -# - https://github.com/compas-dev/compas/issues/649 |
27 | | - |
28 | | -# ============================================================================== |
| 9 | +D = TypeVar("D", bound="Data") |
29 | 10 |
|
30 | 11 |
|
31 | | -class Data(object): |
| 12 | +class Data: |
32 | 13 | """Abstract base class for all COMPAS data objects. |
33 | 14 |
|
34 | 15 | Parameters |
@@ -145,7 +126,7 @@ def __setstate__(self, state): |
145 | 126 | self.name = state["name"] |
146 | 127 |
|
147 | 128 | @classmethod |
148 | | - def __from_data__(cls, data): # type: (dict) -> Data |
| 129 | + def __from_data__(cls, data) -> "Data": |
149 | 130 | """Construct an object of this type from the provided data. |
150 | 131 |
|
151 | 132 | Parameters |
@@ -190,7 +171,7 @@ def name(self, name): |
190 | 171 | self._name = name |
191 | 172 |
|
192 | 173 | @classmethod |
193 | | - def from_json(cls, filepath): # type: (...) -> Data |
| 174 | + def from_json(cls, filepath) -> "Data": |
194 | 175 | """Construct an object of this type from a JSON file. |
195 | 176 |
|
196 | 177 | Parameters |
@@ -232,7 +213,7 @@ def to_json(self, filepath, pretty=False, compact=False, minimal=False): |
232 | 213 | compas.json_dump(self, filepath, pretty=pretty, compact=compact, minimal=minimal) |
233 | 214 |
|
234 | 215 | @classmethod |
235 | | - def from_jsonstring(cls, string): # type: (...) -> Data |
| 216 | + def from_jsonstring(cls, string) -> "Data": |
236 | 217 | """Construct an object of this type from a JSON string. |
237 | 218 |
|
238 | 219 | Parameters |
@@ -276,7 +257,7 @@ def to_jsonstring(self, pretty=False, compact=False, minimal=False): |
276 | 257 | """ |
277 | 258 | return compas.json_dumps(self, pretty=pretty, compact=compact, minimal=minimal) |
278 | 259 |
|
279 | | - def copy(self, cls=None, copy_guid=False): # type: (...) -> D |
| 260 | + def copy(self, cls=None, copy_guid=False) -> D: # type: ignore |
280 | 261 | """Make an independent copy of the data object. |
281 | 262 |
|
282 | 263 | Parameters |
|
0 commit comments