Skip to content

Commit 1a80d00

Browse files
committed
Fix setupotools usage: use find_packages instead of hardcode
1 parent c9cb691 commit 1a80d00

File tree

4 files changed

+46
-18
lines changed

4 files changed

+46
-18
lines changed

CHANGELOG.rst

+9
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
11
CHANGELOG
22
=========
3+
4+
Version 0.5.0
5+
-------------
6+
* _value_ is read-only for class
7+
8+
* Dropped out hardcode from setup.py
9+
10+
* Correct internal class name for BaseBinFieldMeta
11+
312
Version 0.4.0
413
-------------
514
* Mark as beta

TODO.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
* [x] Documentation
2-
* [ ] Examples in documentation
2+
* [x] Examples in documentation
33
* [ ] Unit-test with logwrap package usage

binfield/binfield.py

+29-17
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,18 @@ def _make_mapping_property(key):
256256
)
257257

258258

259+
def _make_static_ro_property(name, val):
260+
"""Property generator for static cases
261+
262+
:type name: str
263+
:type val: object
264+
"""
265+
return property(
266+
fget=lambda _=None: val,
267+
doc="""Read-only {}""".format(name)
268+
)
269+
270+
259271
def _py2_str(src):
260272
"""Convert text to correct python type"""
261273
if not _PY3 and isinstance(src, text_type):
@@ -319,15 +331,9 @@ def __new__(mcs, name, bases, classdict):
319331
if size is None:
320332
size = mask.bit_length()
321333

322-
classdict['_size_'] = property(
323-
fget=lambda _: size,
324-
doc="""Read-only bit length size"""
325-
)
334+
classdict['_size_'] = _make_static_ro_property('size', size)
326335

327-
classdict['_mask_'] = property(
328-
fget=lambda _: mask,
329-
doc="""Read-only data binary mask"""
330-
)
336+
classdict['_mask_'] = _make_static_ro_property('mask', mask)
331337

332338
mapping = classdict.pop('_mapping_', None)
333339

@@ -360,18 +366,18 @@ def __new__(mcs, name, bases, classdict):
360366
ready_mapping = _prepare_mapping(mapping)
361367

362368
if ready_mapping:
363-
classdict['_mapping_'] = property(
364-
fget=lambda _: copy.deepcopy(ready_mapping),
365-
doc="""Read-only mapping structure"""
369+
classdict['_mapping_'] = _make_static_ro_property(
370+
'mapping',
371+
copy.deepcopy(ready_mapping)
366372
)
367373

368374
for m_key in ready_mapping:
369375
classdict[_py2_str(m_key)] = _make_mapping_property(m_key)
370376

371377
else:
372-
classdict['_mapping_'] = property(
373-
fget=lambda _: None,
374-
doc="""Read-only mapping structure"""
378+
classdict['_mapping_'] = _make_static_ro_property(
379+
'mapping',
380+
None
375381
)
376382

377383
classdict['_cache_'] = {} # Use for subclasses memorize
@@ -401,11 +407,17 @@ def makecls(mcs, name, mapping=None, mask=None, size=None):
401407
classdict['_mapping_'] = mapping
402408
return mcs.__new__(mcs, name, (BinField, ), classdict)
403409

410+
@property
411+
def _value_(cls):
412+
return NotImplemented
413+
404414

405415
BaseBinFieldMeta = BinFieldMeta.__new__(
406-
BinFieldMeta,
407-
'intermediate_class', (object, ), {'__slots__': ()}
408-
)
416+
BinFieldMeta,
417+
'BaseBinFieldMeta',
418+
(object, ),
419+
{'__slots__': ()}
420+
)
409421

410422

411423
# noinspection PyRedeclaration

test/test_baseFunc.py

+7
Original file line numberDiff line numberDiff line change
@@ -375,3 +375,10 @@ class IncorrectMaskValue(BinField):
375375
# noinspection PyUnusedLocal
376376
class GarbageData(BinField):
377377
value = 'Not recognized'
378+
379+
class ROValue(BinField):
380+
pass
381+
382+
self.assertEqual(ROValue._value_, NotImplemented)
383+
with self.assertRaises(AttributeError):
384+
ROValue._value_ = 1

0 commit comments

Comments
 (0)