-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: allow forward references in type hints
- Loading branch information
Showing
8 changed files
with
114 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
from questionpy import Attempt, BaseAttemptState, BaseScoringState | ||
|
||
|
||
class MyAttempt(Attempt): | ||
formulation = "" | ||
|
||
def _compute_score(self) -> float: | ||
return 1 | ||
|
||
attempt_state: "MyAttemptState" | ||
scoring_state: "MyScoringState" | ||
|
||
|
||
class MyAttemptState(BaseAttemptState): | ||
pass | ||
|
||
|
||
class MyScoringState(BaseScoringState): | ||
pass | ||
|
||
|
||
def test_should_resolve_forward_references() -> None: | ||
assert MyAttempt.attempt_state_class is MyAttemptState | ||
assert MyAttempt.scoring_state_class is MyScoringState |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import typing | ||
|
||
from questionpy import Attempt, BaseAttemptState, BaseScoringState, Question, BaseQuestionState | ||
from questionpy._qtype import QuestionStateWithVersion | ||
from questionpy.form import FormModel | ||
from tests.questionpy.test_attempt import MyAttempt | ||
|
||
|
||
class MyQuestion(Question): | ||
attempt_class = MyAttempt | ||
|
||
options: "MyFormModel" | ||
question_state: "MyQuestionState" | ||
|
||
|
||
class MyFormModel(FormModel): | ||
pass | ||
|
||
class MyQuestionState(BaseQuestionState): | ||
pass | ||
|
||
|
||
def test_should_resolve_forward_references() -> None: | ||
assert MyQuestion.options_class is MyFormModel | ||
assert MyQuestion.question_state_class is MyQuestionState | ||
assert MyQuestion.question_state_with_version_class is QuestionStateWithVersion[MyFormModel, MyQuestionState] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters