Skip to content

Commit

Permalink
Change types_reflection.py to use thrift-py3 specific thrift types im…
Browse files Browse the repository at this point in the history
…port

Summary:
Previously, thrift py3 container flatnames were made available in auto-migrate mode in D66985311, but only when imported from `.types` rather than `.thrift_types`. In `types_reflection.py` we were importing from `.thrift_types` when building in auto-migrate mode, which meant that the container flatname types were not available, which meant any code trying to introspect on containers wasn't working.

Fixing this by changing the import alias to be `.types` even in auto-migrate mode.

Reviewed By: yoney, prakashgayasen

Differential Revision: D68756851

fbshipit-source-id: 0d26ca0a1c7bc69d55ba831bdb7b137504e3bc66
  • Loading branch information
Filip Francetic authored and facebook-github-bot committed Jan 29, 2025
1 parent 774d26f commit cb9dbc9
Show file tree
Hide file tree
Showing 15 changed files with 13 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ import {{#includeNamespace}}{{value}}.{{/includeNamespace}}types as _{{#includeN
{{/hasTypes?}}
{{/program:includeNamespaces}}
import {{#program:py3Namespaces}}{{value}}.{{/program:py3Namespaces}}{{program:name}}.{{> common/auto_migrate_import_prefix }}types as _{{#program:py3Namespaces}}{{value}}_{{/program:py3Namespaces}}{{program:name}}_types
import {{#program:py3Namespaces}}{{value}}.{{/program:py3Namespaces}}{{program:name}}.types as _{{#program:py3Namespaces}}{{value}}_{{/program:py3Namespaces}}{{program:name}}_types
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

import transitive.types as _transitive_types

import includes.thrift_types as _includes_types
import includes.types as _includes_types



Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

import includes.types as _includes_types

import module.thrift_types as _module_types
import module.types as _module_types



Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
)


import transitive.thrift_types as _transitive_types
import transitive.types as _transitive_types



Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

import transitive.types as _transitive_types

import includes.thrift_types as _includes_types
import includes.types as _includes_types



Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
)


import transitive.thrift_types as _transitive_types
import transitive.types as _transitive_types



Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

import transitive.types as _transitive_types

import includes.thrift_types as _includes_types
import includes.types as _includes_types



Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

import includes.types as _includes_types

import module.thrift_types as _module_types
import module.types as _module_types



Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
import module.types as _module_types
import transitive.types as _transitive_types

import service.thrift_types as _service_types
import service.types as _service_types



Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
)


import transitive.thrift_types as _transitive_types
import transitive.types as _transitive_types



Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
)


import transitive.thrift_types as _transitive_types
import transitive.types as _transitive_types



Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
)


import module.thrift_types as _module_types
import module.types as _module_types



Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
)


import module.thrift_types as _module_types
import module.types as _module_types



Expand Down
5 changes: 0 additions & 5 deletions thrift/lib/py3/test/auto_migrate/converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ def brokenInAutoMigrate(): # pyre-ignore[3] unittest isn't very well typed


class PyDeprecatedToPy3ConverterTest(unittest.TestCase):
@brokenInAutoMigrate()
def test_simple(self) -> None:
simple = py_deprecated_types.Simple(
intField=42,
Expand Down Expand Up @@ -105,19 +104,16 @@ def test_nested(self) -> None:
nested.colorToSimpleMap[py3_types.Color.BLUE].color, py3_types.Color.BLUE
)

@brokenInAutoMigrate()
def test_simple_union(self) -> None:
simple_union = py_deprecated_types.Union(intField=42)._to_py3()
self.assertEqual(simple_union.type, py3_types.Union.Type.intField)
self.assertEqual(simple_union.value, 42)

@brokenInAutoMigrate()
def test_union_with_py3_name_annotation(self) -> None:
simple_union = py_deprecated_types.Union(name="myname")._to_py3()
self.assertEqual(simple_union.type, py3_types.Union.Type.name_)
self.assertEqual(simple_union.value, "myname")

@brokenInAutoMigrate()
def test_union_with_containers(self) -> None:
union_with_list = py_deprecated_types.Union(intList=[1, 2, 3])._to_py3()
self.assertEqual(union_with_list.type, py3_types.Union.Type.intList)
Expand Down Expand Up @@ -187,7 +183,6 @@ def test_union_with_mismatching_field(self) -> None:
self.assertEqual(to.type, py3_types.Potahto.Type.to)
self.assertEqual(to.value, True)

@brokenInAutoMigrate()
def test_py_bad_enum(self) -> None:
simple = py_deprecated_types.Simple(
intField=42,
Expand Down
1 change: 0 additions & 1 deletion thrift/lib/py3/test/auto_migrate/reflection.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@

class ReflectionTests(unittest.TestCase):
# Fails due to containers not working
@brokenInAutoMigrate()
def test_struct(self) -> None:
x = easy(val=1, an_int=Integers(small=300), name="foo", val_list=[1, 2, 3, 4])
self.assertTrue(inspectable(x))
Expand Down

0 comments on commit cb9dbc9

Please sign in to comment.