Skip to content

Commit 61c8abe

Browse files
committed
Don't allow (Named)Tuple to coerce objects to 'object' representation during conversion.
Looks like this was a leftover pathway that we no longer need. The type wrapper for PythonObjectOfType is supposed to do this coersion.
1 parent 9489de7 commit 61c8abe

File tree

3 files changed

+16
-5
lines changed

3 files changed

+16
-5
lines changed

typed_python/compiler/expression_conversion_context.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ def getTypePointer(self, t):
108108
raise Exception(f"Can't give a type pointer to {t} because its not a type")
109109

110110
return native_ast.Expression.GlobalVariable(
111-
name="type_pointer_" + str(id(t)) + "_" + str(t)[:20],
111+
name="type_pointer_" + str(id(t)) + "_" + t.__name__[:50],
112112
type=native_ast.VoidPtr,
113113
metadata=GlobalVariableMetadata.RawTypePointer(
114114
value=t

typed_python/compiler/tests/class_compilation_test.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
typeKnownToCompiler,
4040
SubclassOf,
4141
Held,
42+
NamedTuple
4243
)
4344
import typed_python._types as _types
4445
from typed_python.compiler.runtime import Entrypoint, Runtime, CountCompilationsVisitor
@@ -3016,3 +3017,16 @@ def callf(c: C):
30163017
return c.f(1, None)
30173018

30183019
callf(B())
3020+
3021+
def test_call_method_with_oneof(self):
3022+
N = NamedTuple(x=int)
3023+
3024+
class C(Class):
3025+
def f(self, x: N) -> int:
3026+
return x.x
3027+
3028+
@Entrypoint
3029+
def call(c: C, x: OneOf(None, N)):
3030+
return c.f(x)
3031+
3032+
call(C(), N(x=10))

typed_python/compiler/type_wrappers/tuple_wrapper.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -516,10 +516,7 @@ def convert_to_self_with_target(self, context, targetVal, sourceVal, conversionL
516516
)
517517
)
518518

519-
return sourceVal.convert_to_type(
520-
object,
521-
ConversionLevel.Signature
522-
).convert_to_type_with_target(targetVal, conversionLevel, mayThrowOnFailure)
519+
return super().convert_to_self_with_target(context, targetVal, sourceVal, conversionLevel, mayThrowOnFailure)
523520

524521
def generateConvertOtherTupToSelf(self, context, _, targetVal, sourceVal, conversionLevel):
525522
convertedValues = []

0 commit comments

Comments
 (0)