Skip to content

Commit 1598b1d

Browse files
handling for empty stub classes
1 parent 5c835f3 commit 1598b1d

File tree

4 files changed

+12
-6
lines changed

4 files changed

+12
-6
lines changed

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ classifiers = [
1919
"Programming Language :: Python :: 3.11",
2020
"Programming Language :: Python :: 3.12",
2121
"Programming Language :: Python :: 3.13",
22+
"Programming Language :: Python :: 3.14",
2223
]
2324
dependencies = [
2425
"camel-converter>=3.1.2",

pyya.egg-info/PKG-INFO

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ Classifier: Programming Language :: Python :: 3.10
1717
Classifier: Programming Language :: Python :: 3.11
1818
Classifier: Programming Language :: Python :: 3.12
1919
Classifier: Programming Language :: Python :: 3.13
20+
Classifier: Programming Language :: Python :: 3.14
2021
Requires-Python: >=3.8
2122
Description-Content-Type: text/markdown
2223
Requires-Dist: camel-converter>=3.1.2

pyya/__init__.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ def _model_and_stub_from_dict(
164164
class_name = ''.join(part.capitalize() if i > 0 else part for i, part in enumerate(path + [name])).replace(
165165
'-', '_'
166166
)
167-
stub_lines = [f'class {class_name}(Dict[str, Any]):']
167+
stub_lines = [f'class {class_name}(dict[str, Any]):']
168168
nested_stubs = []
169169
py_type: Any
170170
for section, entry in data.items():
@@ -181,23 +181,25 @@ def _model_and_stub_from_dict(
181181
f'{section.capitalize()}_item', first_item, path + [name]
182182
)
183183
if not keyword.iskeyword(section) and section.isidentifier():
184-
stub_lines.append(f' {section}: List[{class_name + section.capitalize()}_item]')
184+
stub_lines.append(f' {section}: list[{class_name + section.capitalize()}_item]')
185185
nested_stubs.append(nested_stub)
186186
fields[section] = (List[nested_model], entry) # type: ignore
187187
else:
188188
py_type = type(first_item)
189189
if not keyword.iskeyword(section) and section.isidentifier():
190-
stub_lines.append(f' {section}: List[{py_type.__name__}]')
190+
stub_lines.append(f' {section}: list[{py_type.__name__}]')
191191
fields[section] = (List[py_type], entry)
192192
elif isinstance(entry, list):
193193
if not keyword.iskeyword(section) and section.isidentifier():
194-
stub_lines.append(f' {section}: List[Any]')
194+
stub_lines.append(f' {section}: list[Any]')
195195
fields[section] = (List[Any], entry)
196196
else:
197197
py_type = type(entry)
198198
if not keyword.iskeyword(section) and section.isidentifier():
199199
stub_lines.append(f' {section}: {py_type.__name__}')
200200
fields[section] = (py_type, entry)
201+
if len(stub_lines) == 1:
202+
stub_lines[0] += ' ...'
201203
stub_code = '\n\n'.join(nested_stubs + ['\n'.join(stub_lines)])
202204
return create_model(name, **fields, __base__=ExtraBase), stub_code
203205

@@ -236,7 +238,9 @@ def _get_default_raw_data() -> ConfigType:
236238
_default_raw_data = _get_default_raw_data()
237239
_, stub = _model_and_stub_from_dict('Config', _default_raw_data)
238240
stub_full = (
239-
f'# {output_file} was autogenerated from {default_config} with pyya CLI tool, see `pyya -h`\nfrom typing import Any, Dict, List\n\n'
241+
f'# {output_file} was autogenerated from {default_config} with pyya CLI tool, see `pyya -h`\n'
242+
f'from __future__ import annotations\n\n'
243+
f'from typing import Any\n\n'
240244
f'{stub}\n\n'
241245
'# for type hints to work the variable name created with pyya.init_config\n'
242246
'# should have the same name (e.g. config = pyya.init_config())\n'

uv.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)