Skip to content

Commit 31e34ea

Browse files
author
Michael Schneeberger
committed
rename dataclass_abc to dataclassabc
1 parent bce6a2b commit 31e34ea

File tree

6 files changed

+17
-147
lines changed

6 files changed

+17
-147
lines changed

README.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,21 +8,21 @@ Library that lets you define abstract properties for dataclasses.
88

99
## Usage
1010

11-
The `dataclass_abc` class decorator resolves the abstract properties
11+
The `dataclassabc` class decorator resolves the abstract properties
1212
overwritten by a field.
1313

1414
``` python
1515
from abc import ABC, abstractmethod
1616

17-
from dataclass_abc import dataclass_abc
17+
from dataclassabc import dataclassabc
1818

1919
class A(ABC):
2020
@property
2121
@abstractmethod
2222
def name(self) -> str:
2323
...
2424

25-
@dataclass_abc(frozen=True)
25+
@dataclassabc(frozen=True)
2626
class B(A):
2727
name: str # overwrites the abstract property 'name' in 'A'
2828
```
@@ -35,7 +35,7 @@ Define a mutable variable `name` in the abstract class `A` by using the
3535
``` python
3636
from abc import ABC, abstractmethod
3737

38-
from dataclass_abc import dataclass_abc
38+
from dataclassabc import dataclassabc
3939

4040
class A(ABC):
4141
@property
@@ -51,7 +51,7 @@ class A(ABC):
5151
def set_name(self, val: str):
5252
self.name = val
5353

54-
@dataclass_abc
54+
@dataclassabc
5555
class B(A):
5656
name: str
5757

@@ -76,7 +76,7 @@ properties and methods based on the abstract properties.
7676
e.g. using `isinstance` method.
7777
- **impl** - an *implementation class* implements the abstract properties.
7878
(see `CityImpl` or `CapitalCityImpl` in the example). This class is decorated with
79-
`dataclass_abc` and `resolve_abc_prop` and should always be called through an
79+
`dataclassabc` and `resolve_abc_prop` and should always be called through an
8080
*initialize function*.
8181
- **init** - an *initialize function* (or *constructor function*) initializes an
8282
*implementation class*.
Lines changed: 2 additions & 132 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ def set_func(self, val, key=key):
6565
return new_cls
6666

6767

68-
def dataclass_abc(_cls=None, /, *, init=True, repr=True, eq=True, order=False,
68+
def dataclassabc(_cls=None, /, *, init=True, repr=True, eq=True, order=False,
6969
unsafe_hash=False, frozen=False, match_args=True,
7070
kw_only=False, slots=False, weakref_slot=False):
7171
"""
@@ -78,7 +78,7 @@ class A(ABC):
7878
def name(self) -> str:
7979
...
8080
81-
@dataclass_abc(frozen=True)
81+
@dataclassabc(frozen=True)
8282
class B(A):
8383
name: str
8484
```
@@ -152,133 +152,3 @@ def gen_fields():
152152
return wrap(_cls)
153153

154154

155-
# def create_class(
156-
# name: str,
157-
# mixins: tuple[str],
158-
# path: str,
159-
# overwrite: bool = None,
160-
# ):
161-
# """
162-
163-
# """
164-
165-
# impl_class_name = f'{name}Impl'
166-
# init_func_name = 'init_' + '_'.join(re.findall('[A-Z][^A-Z]*', name)).lower()
167-
# init_file_name = init_func_name.replace('_', '')
168-
169-
# main_rel_import = f'{name.lower()}'
170-
# impl_rel_import = ('impl', f'{impl_class_name.lower()}')
171-
# init_rel_import = ('init', f'{init_file_name}')
172-
173-
# mixins_import = f'{path}.mixins'
174-
# main_import = f'{path}.{name.lower()}'
175-
# impl_import = '.'.join((path,) + impl_rel_import)
176-
177-
# folder_path = os.path.dirname(importlib.import_module(path).__file__)
178-
179-
# main_file_path = os.path.join(folder_path, f'{main_rel_import}.py')
180-
# impl_folder_path = os.path.join(folder_path, impl_rel_import[0])
181-
# impl_file_path = os.path.join(impl_folder_path, f'{impl_rel_import[1]}.py')
182-
# init_folder_path = os.path.join(folder_path, init_rel_import[0])
183-
# init_file_path = os.path.join(init_folder_path, f'{init_rel_import[1]}.py')
184-
185-
# if not overwrite:
186-
# for folder_path in (main_file_path, impl_file_path, init_file_path):
187-
# assert not os.path.exists(folder_path), f'"{folder_path}" already exists'
188-
189-
# # make sure the mixins exists
190-
# def gen_mixin_imports():
191-
# for mixin_name in mixins:
192-
193-
# mixin_import_path = f'{mixins_import}.{mixin_name.lower()}'
194-
195-
# mod = importlib.import_module(mixin_import_path)
196-
# assert hasattr(mod, mixin_name), f'Mixin "{mixin_name}" does not exist'
197-
198-
# yield mixin_name, mixin_import_path
199-
200-
# mixins_info = tuple(gen_mixin_imports())
201-
202-
# # main class
203-
# # ----------
204-
205-
# with open(main_file_path, 'w') as f:
206-
207-
# for mixin_name, mixin_import_path in mixins_info:
208-
# f.write(f'from {mixin_import_path} import {mixin_name} \n')
209-
210-
# f.write('\n')
211-
212-
# extends_from_mixins = ', '.join(mixins)
213-
# f.write(f'class {name}({extends_from_mixins}):\n\tpass\n')
214-
215-
# # dataclass implementation
216-
# # ------------------------
217-
218-
# if not os.path.exists(impl_folder_path):
219-
# os.makedirs(impl_folder_path)
220-
# open(f'{impl_folder_path}/__init__.py', 'a').close()
221-
222-
# def gen_fields():
223-
# mod = importlib.import_module(main_import)
224-
# for class_obj in getattr(mod, name).__mro__:
225-
# for key, value in class_obj.__dict__.items():
226-
# if hasattr(value, '__isabstractmethod__') and getattr(value, '__isabstractmethod__') and isinstance(value, property):
227-
# type_hint = typing.get_type_hints(value.fget)['return']
228-
# yield key, type_hint.__module__, type_hint.__qualname__
229-
230-
# fields = tuple(gen_fields())
231-
# import_type_hints = set((module, cls_name) for _, module, cls_name in fields)
232-
233-
# with open(impl_file_path, 'w') as f:
234-
235-
# f.write(f'import dataclass_abc\n')
236-
# f.write(f'from {main_import} import {name} \n')
237-
238-
# f.write('\n')
239-
240-
# for module, cls_name in import_type_hints:
241-
# if module != 'builtins':
242-
# f.write(f'from {module} import {cls_name} \n')
243-
244-
# f.write('\n')
245-
246-
# f.write(f'@dataclass_abc.dataclass_abc(frozen=True)\n')
247-
# f.write(f'class {impl_class_name}({name}):\n')
248-
249-
# for field_name, module, cls_name in fields:
250-
# f.write(f'\t{field_name}: {cls_name}\n')
251-
252-
# # init_function
253-
# # -------------
254-
255-
# if not os.path.exists(init_folder_path):
256-
# os.makedirs(init_folder_path)
257-
# open(f'{init_folder_path}/__init__.py', 'a').close()
258-
259-
# with open(init_file_path, 'w') as f:
260-
261-
# init_func_name = '_'.join(re.findall('[A-Z][^A-Z]*', name)).lower()
262-
263-
# for module, cls_name in import_type_hints:
264-
# if module != 'builtins':
265-
# f.write(f'from {module} import {cls_name}\n')
266-
267-
# f.write(f'from {impl_import} import {impl_class_name}\n')
268-
269-
# f.write('\n')
270-
# f.write('\n')
271-
272-
# f.write(f'def init_{init_func_name}(\n')
273-
274-
# for field_name, module, cls_name in fields:
275-
# f.write(f'\t\t{field_name}: {cls_name},\n')
276-
277-
# f.write(f'):\n')
278-
279-
# f.write(f'\treturn {impl_class_name}(\n')
280-
281-
# for field_name, module, cls_name in fields:
282-
# f.write(f'\t\t{field_name}={field_name},\n')
283-
284-
# f.write(f')\n')

example/impl/capitalcityimpl.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
from dataclass_abc import dataclass_abc
1+
from dataclassabc import dataclassabc
22
from example.capitalcity import CapitalCity
33

44

5-
@dataclass_abc
5+
@dataclassabc
66
class CapitalCityImpl(CapitalCity):
77
city_name: str
88
lon: float

example/impl/cityimpl.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
from dataclass_abc import dataclass_abc
1+
from dataclassabc import dataclassabc
22
from example.city import City
33

44

5-
@dataclass_abc
5+
@dataclassabc
66
class CityImpl(City):
77
city_name: str
88
lon: float

setup.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
long_description = f.read()
1010

1111
setup(
12-
name='dataclass_abc',
13-
version='0.0.7',
12+
name='dataclass-abc',
13+
version='0.0.8',
1414
description='Library that lets you define abstract properties for dataclasses.',
1515
long_description=long_description,
1616
long_description_content_type='text/markdown',
@@ -21,7 +21,7 @@
2121
'License :: OSI Approved :: MIT License',
2222
'Programming Language :: Python :: 3.11',
2323
],
24-
keywords='dataclass_abc abstract abc property',
25-
packages=['dataclass_abc'],
24+
keywords='dataclass-abc abstract abc property',
25+
packages=['dataclassabc'],
2626
python_requires='>=3.10',
2727
)

tests/test_resolveabcprop.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
from abc import ABC, abstractmethod
33
from dataclasses import dataclass
44

5-
from dataclass_abc import resolve_abc_prop
5+
from dataclassabc import resolve_abc_prop
66

77

88
class TestResolveABCProp(unittest.TestCase):

0 commit comments

Comments
 (0)