Skip to content

Commit 076765a

Browse files
refactor: define parameter types and change name of a variable
1 parent 30cecf4 commit 076765a

File tree

1 file changed

+14
-9
lines changed

1 file changed

+14
-9
lines changed

grader_service/handlers/config.py

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,28 @@
1+
import traitlets.config
2+
3+
from grader_service.autograding.kube.kube_grader import KubeAutogradeExecutor
4+
from grader_service.autograding.local_grader import LocalAutogradeExecutor
15
from grader_service.handlers.base_handler import GraderBaseHandler, authorize
26
from grader_service.orm.takepart import Scope
37
from grader_service.registry import VersionSpecifier, register_handler
48

59

6-
def _get_effective_executor_value(app_cfg, executor_class, trait_name):
10+
def _get_effective_executor_value(
11+
app_cfg: traitlets.config.Config,
12+
executor_class: type[LocalAutogradeExecutor] | type[KubeAutogradeExecutor],
13+
trait_name,
14+
):
715
"""
816
Return the configured value for trait_name if present in app_cfg,
917
otherwise return the class default pulled from the trait metadata.
1018
"""
11-
# app_cfg is a traitlets.config.Config object (mapping-like)
12-
# executor_class is the class (LocalAutogradeExecutor or similar)
1319

14-
# 1) look up the per-class node as a mapping (not attribute access)
15-
user_node = app_cfg.get(executor_class.__name__, None)
20+
# 1) retrieve the provided class field from the config
21+
executor_class_field = app_cfg.get(executor_class.__name__, None)
1622

17-
# user_node may be None, or a Config object / dict-like. Use mapping access.
18-
if user_node is not None and trait_name in user_node:
19-
# Use .get to return the exact user-supplied value (won't be a lazy object)
20-
return user_node.get(trait_name)
23+
# executor_class_field may be None, or a Config object / dict-like. Use mapping access.
24+
if executor_class_field is not None and trait_name in executor_class_field:
25+
return executor_class_field.get(trait_name)
2126

2227
# 2) fallback to the trait's default from the class metadata
2328
return executor_class.class_traits()[trait_name].default()

0 commit comments

Comments
 (0)