-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into feature/05-attempt-II
- Loading branch information
Showing
8 changed files
with
66 additions
and
4 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
from typing import Any, Optional | ||
|
||
from untypy.interfaces import TypeChecker, TypeCheckerFactory, CreationContext | ||
|
||
|
||
class StringForwardRefFactory(TypeCheckerFactory): | ||
def create_from(self, annotation: Any, ctx: CreationContext) -> Optional[TypeChecker]: | ||
if type(annotation) is str: | ||
eval_args = [annotation, globals()] | ||
local = ctx.eval_context() | ||
if local is not None: | ||
eval_args.append(local) | ||
annotation = eval(*eval_args) | ||
return ctx.find_checker(annotation) |
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,12 @@ | ||
Traceback (most recent call last): | ||
File "test-data/testForwardRef5.py", line 23, in <module> | ||
for car in garage.cars: | ||
WyppTypeError: got value of wrong type | ||
given: 'Not A Car' | ||
expected: value of type Car | ||
|
||
context: record constructor Garage(cars: list[Car]) -> Self | ||
^^^ | ||
declared at: test-data/testForwardRef5.py:9 | ||
caused by: test-data/testForwardRef5.py:23 | ||
| for car in garage.cars: |
Empty file.
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 @@ | ||
# See https://github.com/skogsbaer/write-your-python-program/issues/62 | ||
|
||
from wypp import * | ||
|
||
@record | ||
class Car: | ||
color: str | ||
|
||
@record | ||
class Garage: | ||
cars: list['Car'] | ||
|
||
class CarManager: | ||
def store(self, car : set['Car'], garage :'Garage') -> 'CarManager': | ||
return self | ||
|
||
garage = Garage(cars=[Car(color='red'), Car(color='blue')]) | ||
for car in garage.cars: | ||
pass | ||
|
||
# trigger error | ||
garage = Garage(cars=[Car(color='red'), "Not A Car"]) | ||
for car in garage.cars: | ||
pass |