Skip to content

Commit 4cdef8b

Browse files
committed
Avoid using dataclass
1 parent 5a9817d commit 4cdef8b

1 file changed

Lines changed: 29 additions & 27 deletions

File tree

pygmt/alias.py

Lines changed: 29 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
The PyGMT alias system to convert PyGMT's long-form arguments to GMT's short-form.
33
"""
44

5-
import dataclasses
65
from collections.abc import Mapping, Sequence
76
from typing import Any, Literal
87

@@ -134,12 +133,11 @@ def _to_string(
134133
return f"{prefix}{_value}"
135134

136135

137-
@dataclasses.dataclass
138136
class Alias:
139137
"""
140138
Class for aliasing a PyGMT parameter to a GMT option or a modifier.
141139
142-
Attributes
140+
Parameters
143141
----------
144142
value
145143
The value of the alias.
@@ -152,9 +150,9 @@ class Alias:
152150
separator
153151
The separator to use if the value is a sequence.
154152
size
155-
Expected size of the 1-D sequence. It can be either an integer or a sequence of
156-
integers. If an integer, it is the expected size of the 1-D sequence. If it is a
157-
sequence, it is the allowed size of the 1-D sequence.
153+
Expected size of the 1-D sequence. It can be either an integer or a sequence
154+
of integers. If an integer, it is the expected size of the 1-D sequence.
155+
If it is a sequence, it is the allowed sizes of the 1-D sequence.
158156
ndim
159157
The expected maximum number of dimensions of the sequence.
160158
@@ -173,25 +171,29 @@ class Alias:
173171
['xaf', 'yaf', 'WSen']
174172
"""
175173

176-
value: Any
177-
name: str | None = None
178-
prefix: str = ""
179-
mapping: Mapping | None = None
180-
separator: Literal["/", ","] | None = None
181-
size: int | Sequence[int] | None = None
182-
ndim: int = 1
183-
184-
@property
185-
def _value(self) -> str | list[str] | None:
186-
"""
187-
The value of the alias as a string, a sequence of strings or None.
188-
"""
189-
return _to_string(
190-
value=self.value,
191-
name=self.name,
192-
prefix=self.prefix,
193-
mapping=self.mapping,
194-
separator=self.separator,
195-
size=self.size,
196-
ndim=self.ndim,
174+
def __init__(
175+
self,
176+
value: Any,
177+
name: str | None = None,
178+
prefix: str = "",
179+
mapping: Mapping | None = None,
180+
separator: Literal["/", ","] | None = None,
181+
size: int | Sequence[int] | None = None,
182+
ndim: int = 1,
183+
):
184+
self.value = value
185+
self.name = name
186+
self.prefix = prefix
187+
self.mapping = mapping
188+
self.separator = separator
189+
self.size = size
190+
self.ndim = ndim
191+
self._value = _to_string(
192+
value=value,
193+
name=name,
194+
prefix=prefix,
195+
mapping=mapping,
196+
separator=separator,
197+
size=size,
198+
ndim=ndim,
197199
)

0 commit comments

Comments
 (0)