Skip to content

Commit 79ba21a

Browse files
authored
Fix Type Hints (#38)
1 parent a7f53d7 commit 79ba21a

File tree

3 files changed

+21
-19
lines changed

3 files changed

+21
-19
lines changed

cppython/project.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,9 @@ class ProjectBuilder:
3636
def __init__(self, configuration: ProjectConfiguration) -> None:
3737
self.configuration = configuration
3838

39-
def gather_plugins(self, plugin_type: Type[Plugin]) -> list[Type[Plugin]]:
39+
DerivedPlugin = TypeVar("DerivedPlugin", bound=Plugin)
40+
41+
def gather_plugins(self, plugin_type: Type[DerivedPlugin]) -> list[Type[DerivedPlugin]]:
4042
"""
4143
TODO
4244
"""
@@ -50,29 +52,29 @@ def gather_plugins(self, plugin_type: Type[Plugin]) -> list[Type[Plugin]]:
5052

5153
return plugins
5254

53-
def generate_model(self, plugins: list[Type[Plugin]]) -> Type[PyProject]:
55+
def generate_model(self, plugins: list[Type[Generator]]) -> Type[PyProject]:
5456
"""
5557
TODO
5658
"""
5759
plugin_fields = {}
5860
for plugin_type in plugins:
5961
plugin_fields[plugin_type.name()] = plugin_type.data_type()
6062

61-
ExtendedCPPythonData = create_model(
63+
extended_cppython_type = create_model(
6264
"ExtendedCPPythonData",
6365
**plugin_fields,
6466
__base__=CPPythonData,
6567
)
6668

67-
ExtendedToolData = create_model(
69+
extended_tool_type = create_model(
6870
"ToolData",
69-
cppython=ExtendedCPPythonData,
71+
cppython=extended_cppython_type,
7072
__base__=ToolData,
7173
)
7274

7375
return create_model(
7476
"PyProject",
75-
tool=ExtendedToolData,
77+
tool=extended_tool_type,
7678
__base__=PyProject,
7779
)
7880

@@ -110,8 +112,8 @@ def __init__(
110112
interface.print("No generator plugin was found.")
111113
return
112114

113-
ExtendedPyProject = builder.generate_model(plugins)
114-
pyproject = ExtendedPyProject(**pyproject_data)
115+
extended_pyproject_type = builder.generate_model(plugins)
116+
pyproject = extended_pyproject_type(**pyproject_data)
115117

116118
if pyproject.tool is None:
117119
if self.configuration.verbose:

pdm.lock

Lines changed: 7 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/unit/test_project.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,18 +47,18 @@ def test_generator_data_construction(self, mocker: MockerFixture):
4747

4848
configuration = ProjectConfiguration()
4949
builder = ProjectBuilder(configuration)
50-
Model = builder.generate_model([])
50+
model_type = builder.generate_model([])
5151

52-
assert Model.__base__ == PyProject
52+
assert model_type.__base__ == PyProject
5353

5454
generator = mocker.Mock(spec=Generator)
5555
generator_data = mocker.Mock(spec=GeneratorData)
5656

5757
generator.name.return_value = "mock"
5858
generator.data_type.return_value = type(generator_data)
59-
Model = builder.generate_model([generator])
59+
model_type = builder.generate_model([generator])
6060

61-
assert Model.__base__ == PyProject
61+
assert model_type.__base__ == PyProject
6262

6363
def test_generator_creation(self, mocker: MockerFixture):
6464
"""

0 commit comments

Comments
 (0)