Skip to content

Commit c104174

Browse files
authored
fix: typebuilder imports (#2209)
<!-- ELLIPSIS_HIDDEN --> > [!IMPORTANT] > Fix import issues in TypeBuilder files and add tests to verify correct imports and functionality. > > - **Imports**: > - Add imports for `FieldType`, `EnumValueBuilder`, `EnumBuilder`, and `ClassBuilder` in `type_builder.py.j2` and `type_builder.ts.j2`. > - Export `FieldType`, `EnumBuilder`, and `ClassBuilder` in `type_builder.ts.j2` and `type_builder.ts` in `typescript-esm` and `typescript`. > - **Tests**: > - Add `test_typebuilder_and_fieldtype_imports` in `test_typebuilder.py` to verify imports of `TypeBuilder` and `FieldType`. > - Add import tests in `dynamic-types.test.ts` to ensure `TypeBuilder` and `FieldType` are correctly imported and functional. > > <sup>This description was created by </sup>[<img alt="Ellipsis" src="https://img.shields.io/badge/Ellipsis-blue?color=175173">](https://www.ellipsis.dev?ref=BoundaryML%2Fbaml&utm_source=github&utm_medium=referral)<sup> for 4326ab2. You can [customize](https://app.ellipsis.dev/BoundaryML/settings/summaries) this summary. It will automatically update as commits are pushed.</sup> <!-- ELLIPSIS_HIDDEN -->
1 parent 2a031b6 commit c104174

9 files changed

Lines changed: 51 additions & 0 deletions

File tree

‎engine/generators/languages/python/src/_templates/type_builder.py.j2‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import typing
22
from baml_py import type_builder
33
from baml_py import baml_py
4+
# These are exports, not used here, hence the linter is disabled
5+
from baml_py.baml_py import FieldType, EnumValueBuilder, EnumBuilder, ClassBuilder # noqa: F401 # pylint: disable=unused-import
46
from .globals import DO_NOT_USE_DIRECTLY_UNLESS_YOU_KNOW_WHAT_YOURE_DOING_RUNTIME
57

68
class TypeBuilder(type_builder.TypeBuilder):

‎engine/generators/languages/typescript/src/_templates/type_builder.ts.j2‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ import { FieldType } from '@boundaryml/baml/native'
22
import { TypeBuilder as _TypeBuilder, EnumBuilder, EnumViewer, ClassBuilder, ClassViewer } from '@boundaryml/baml/type_builder'
33
import { DO_NOT_USE_DIRECTLY_UNLESS_YOU_KNOW_WHAT_YOURE_DOING_RUNTIME } from "./globals"
44

5+
export { FieldType, EnumBuilder, ClassBuilder }
6+
57
export default class TypeBuilder {
68
private tb: _TypeBuilder;
79
{% for cls in classes %}

‎integ-tests/python-v1/baml_client/type_builder.py‎

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎integ-tests/python/baml_client/type_builder.py‎

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎integ-tests/python/tests/test_typebuilder.py‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -524,3 +524,22 @@ async def test_referencing_existing_class_types():
524524
tb = TypeBuilder()
525525
# useful for adding dynamic tools for example
526526
tb.Person.add_property("props", tb.union([tb.Resume.type(), tb.Hobby.type()]))
527+
528+
529+
def test_typebuilder_and_fieldtype_imports():
530+
"""Test that both TypeBuilder and FieldType can be imported from baml_client.type_builder"""
531+
# Test importing both from the same module
532+
from baml_client.type_builder import TypeBuilder, FieldType
533+
534+
# Verify TypeBuilder works
535+
tb = TypeBuilder()
536+
assert tb is not None
537+
assert isinstance(tb, TypeBuilder)
538+
539+
# Verify FieldType is available
540+
assert FieldType is not None
541+
542+
# Test that TypeBuilder methods return FieldType instances
543+
string_type = tb.string()
544+
assert isinstance(string_type, FieldType)
545+

‎integ-tests/react/baml_client/type_builder.ts‎

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎integ-tests/typescript-esm/baml_client/type_builder.ts‎

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎integ-tests/typescript/baml_client/type_builder.ts‎

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎integ-tests/typescript/tests/dynamic-types.test.ts‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,25 @@
11
import TypeBuilder from "../baml_client/type_builder";
2+
import { FieldType } from "../baml_client/type_builder";
23
import { b } from "./test-setup";
34

45
describe("Dynamic Type Tests", () => {
6+
describe("Import Tests", () => {
7+
it("should import TypeBuilder and FieldType from type_builder module", () => {
8+
// Test that TypeBuilder is importable
9+
const tb = new TypeBuilder();
10+
expect(tb).toBeInstanceOf(TypeBuilder);
11+
12+
// Test that FieldType is importable and works
13+
expect(FieldType).toBeDefined();
14+
15+
// Test that TypeBuilder methods return FieldType instances
16+
const stringType = tb.string();
17+
// TypeScript will ensure type safety at compile time
18+
// This test verifies runtime behavior
19+
expect(stringType).toBeDefined();
20+
});
21+
});
22+
523
describe("Basic Dynamic Types", () => {
624
it("should work with dynamic types single", async () => {
725
let tb = new TypeBuilder();

0 commit comments

Comments
 (0)