@@ -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')
0 commit comments