Skip to content

Commit 4c87c51

Browse files
committed
Remove of deprecated lazy_property
1 parent 4db50aa commit 4c87c51

2 files changed

Lines changed: 18 additions & 23 deletions

File tree

src/odin/codecs/csv_codec.py

Lines changed: 14 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,17 @@
1414
...
1515
1616
"""
17+
1718
import csv
19+
from functools import cached_property
1820
from io import StringIO
1921

2022
from odin import bases
2123
from odin.datastructures import CaseLessStringList
2224
from odin.exceptions import CodecDecodeError, ValidationError
2325
from odin.fields import NotProvided
2426
from odin.resources import create_resource_from_iter
25-
from odin.utils import getmeta, lazy_property
27+
from odin.utils import getmeta
2628

2729
CONTENT_TYPE = "text/csv"
2830

@@ -167,37 +169,29 @@ def _create_reader(self, f, kwargs):
167169
return self.csv_reader(f, self.csv_dialect, **kwargs)
168170

169171
def _read_header(self):
170-
"""
171-
Get the header, this needs to be called **once** only!
172-
"""
172+
"""Get the header, this needs to be called **once** only!"""
173173
header = next(self._reader)
174174
if self.ignore_header_case:
175175
header = CaseLessStringList(header)
176176
return header
177177

178-
@lazy_property
178+
@cached_property
179179
def field_names(self):
180-
"""
181-
Field names from resource.
182-
"""
180+
"""Field names from resource."""
183181
fields = getmeta(self.resource_type).fields
184182
if self.ignore_header_case:
185183
return CaseLessStringList(field.name for field in fields)
186184
else:
187185
return tuple(field.name for field in fields)
188186

189-
@lazy_property
187+
@cached_property
190188
def extra_field_names(self):
191-
"""
192-
Extra fields not included in header
193-
"""
189+
"""Extra fields not included in header."""
194190
return tuple(field for field in self.header if field not in self.field_names)
195191

196-
@lazy_property
192+
@cached_property
197193
def field_mapping(self):
198-
"""
199-
Index mapping of CSV fields to resource fields.
200-
"""
194+
"""Index mapping of CSV fields to resource fields."""
201195
mapping = []
202196

203197
# Add expected fields
@@ -215,15 +209,15 @@ def field_mapping(self):
215209
return tuple(mapping)
216210

217211

218-
def reader(
212+
def reader( # noqa: PLR0913
219213
f,
220214
resource,
221215
includes_header=False,
222216
csv_module=csv,
223217
full_clean=True,
224218
ignore_header_case=False,
225219
strict_fields=False,
226-
**kwargs
220+
**kwargs,
227221
):
228222
"""
229223
CSV reader that returns resource objects
@@ -248,7 +242,7 @@ def reader(
248242
includes_header=includes_header,
249243
ignore_header_case=ignore_header_case,
250244
strict_fields=strict_fields,
251-
**kwargs
245+
**kwargs,
252246
)
253247

254248

@@ -266,7 +260,7 @@ def _get_resource_type(resources, resource_type):
266260
return resource_type or resources.resource_type
267261
elif isinstance(resources, bases.ResourceIterable) and resource_type:
268262
return resource_type
269-
elif isinstance(resources, (list, tuple)):
263+
elif isinstance(resources, list | tuple):
270264
if not len(resources):
271265
return
272266
# Use first resource to obtain field list

src/odin/proxy.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,13 @@
88
99
"""
1010

11+
from functools import cached_property
1112
from typing import Union
1213

1314
from odin import registration
1415
from odin.bases import TypedResourceIterable
1516
from odin.resources import ResourceBase, ResourceOptions
16-
from odin.utils import filter_fields, getmeta, lazy_property
17+
from odin.utils import filter_fields, getmeta
1718

1819
EMPTY = ()
1920

@@ -132,12 +133,12 @@ def contribute_to_class(self, cls, _): # noqa: PLR0912
132133
for attr_name, value in proxy_attrs.items():
133134
setattr(self, attr_name, value)
134135

135-
@lazy_property
136+
@cached_property
136137
def readonly_fields(self):
137138
"""Fields that can only be read from."""
138139
return tuple(f for f in self.fields if f.attname in self.readonly)
139140

140-
@lazy_property
141+
@cached_property
141142
def init_fields(self):
142143
"""Fields used in the resource init."""
143144
return tuple(f for f in self.fields if f.attname not in self.readonly)

0 commit comments

Comments
 (0)