Skip to content

Commit

Permalink
Rename String LitType to StringLitType.
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 462458130
  • Loading branch information
cjqian authored and LIT team committed Jul 21, 2022
1 parent c1683ff commit 72edd26
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 26 deletions.
8 changes: 4 additions & 4 deletions lit_nlp/api/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ def all_subclasses(cls):


@attr.s(auto_attribs=True, frozen=True, kw_only=True)
class String(LitType):
class StringLitType(LitType):
"""User-editable text input.
All automated edits are disabled for this type.
Expand All @@ -155,7 +155,7 @@ class String(LitType):


@attr.s(auto_attribs=True, frozen=True, kw_only=True)
class TextSegment(String):
class TextSegment(StringLitType):
"""Text input (untokenized), a single string."""
pass

Expand Down Expand Up @@ -281,7 +281,7 @@ class ReferenceScores(_List):


@attr.s(auto_attribs=True, frozen=True, kw_only=True)
class CategoryLabel(String):
class CategoryLabel(StringLitType):
"""Category or class label, a single string."""
# Optional vocabulary to specify allowed values.
# If omitted, any value is accepted.
Expand Down Expand Up @@ -548,4 +548,4 @@ class InfluentialExamples(LitType):
pass


# LINT.ThenChange(../client/lib/types.ts)
# LINT.ThenChange(../client/lib/lit_types.ts)
2 changes: 1 addition & 1 deletion lit_nlp/api/types_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def test_num_littypes(self):
self.assertEqual(num_types, NUM_TYPES)

def test_inherit_parent_default_type(self):
lit_type = types.String()
lit_type = types.StringLitType()
self.assertIsInstance(lit_type.default, str)

def test_inherit_parent_default_value(self):
Expand Down
6 changes: 3 additions & 3 deletions lit_nlp/client/lib/lit_types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,15 +66,15 @@ export class LitType {
* A string LitType.
*/
@registered
export class String extends LitType {
export class StringLitType extends LitType {
override default: string = '';
}

/**
* Text input (untokenized), a single string.
*/
@registered
export class TextSegment extends String {
export class TextSegment extends StringLitType {
}

/**
Expand Down Expand Up @@ -219,7 +219,7 @@ export class ReferenceScores extends _List {
* Category or class label, a single string.
*/
@registered
export class CategoryLabel extends String {
export class CategoryLabel extends StringLitType {
/**
* Optional vocabulary to specify allowed values.
* If omitted, any value is accepted.
Expand Down
4 changes: 2 additions & 2 deletions lit_nlp/client/lib/lit_types_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ import * as litTypes from './lit_types';

describe('creates lit types', () => {
it('with the correct inheritance', () => {
const testString = new litTypes.String();
const testString = new litTypes.StringLitType();
testString.default = 'string value';

expect(testString.default).toBe('string value');
expect(testString.required).toBe(true);

expect(testString instanceof litTypes.String).toBe(true);
expect(testString instanceof litTypes.StringLitType).toBe(true);
expect(testString instanceof litTypes.LitType).toBe(true);
expect(testString instanceof litTypes.Scalar).toBe(false);
});
Expand Down
28 changes: 14 additions & 14 deletions lit_nlp/client/lib/lit_types_utils_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@ describe('createLitType test', () => {
});

it('creates with constructor params', () => {
const expected = new litTypes.String();
expected.__name__ = 'String';
expected.__mro__ = ['String', 'LitType', 'Object'];
const expected = new litTypes.StringLitType();
expected.__name__ = 'StringLitType';
expected.__mro__ = ['StringLitType', 'LitType', 'Object'];
expected.default = 'foo';
expected.show_in_data_table = true;

const result = litTypesUtils.createLitType(
'String', {'show_in_data_table': true, 'default': 'foo'});
'StringLitType', {'show_in_data_table': true, 'default': 'foo'});
expect(result).toEqual(expected);
});

Expand All @@ -37,7 +37,7 @@ describe('createLitType test', () => {
});

it('handles invalid constructor params', () => {
expect(() => litTypesUtils.createLitType('String', {
expect(() => litTypesUtils.createLitType('StringLitType', {
'notAStringParam': true
})).toThrowError();
});
Expand All @@ -57,9 +57,9 @@ describe('createLitType test', () => {
});

it('populates mro', () => {
let testType = new litTypes.String();
let testType = new litTypes.StringLitType();
expect(litTypesUtils.getMethodResolutionOrder(testType)).toEqual([
'String', 'LitType', 'Object'
'StringLitType', 'LitType', 'Object'
]);

testType = new litTypes.LitType();
Expand All @@ -75,9 +75,9 @@ describe('createLitType test', () => {

describe('isLitSubtype test', () => {
it('checks is lit subtype', () => {
const testType = new litTypes.String();
expect(litTypesUtils.isLitSubtype(testType, 'String')).toBe(true);
expect(litTypesUtils.isLitSubtype(testType, ['String'])).toBe(true);
const testType = new litTypes.StringLitType();
expect(litTypesUtils.isLitSubtype(testType, 'StringLitType')).toBe(true);
expect(litTypesUtils.isLitSubtype(testType, ['StringLitType'])).toBe(true);
expect(litTypesUtils.isLitSubtype(testType, ['Scalar'])).toBe(false);

// LitType is not a subtype of LitType.
Expand All @@ -93,19 +93,19 @@ describe('findSpecKeys test', () => {
// TODO(cjqian): Add original utils_test test after adding more types.
const spec: Spec = {
'scalar_foo': new litTypes.Scalar(),
'segment': new litTypes.String(),
'generated_text': new litTypes.String(),
'segment': new litTypes.StringLitType(),
'generated_text': new litTypes.StringLitType(),
};


it('finds all spec keys that match the specified types', () => {
// Key is in spec.
expect(litTypesUtils.findSpecKeys(spec, 'String')).toEqual([
expect(litTypesUtils.findSpecKeys(spec, 'StringLitType')).toEqual([
'segment', 'generated_text'
]);

// Keys are in spec.
expect(litTypesUtils.findSpecKeys(spec, ['String', 'Scalar'])).toEqual([
expect(litTypesUtils.findSpecKeys(spec, ['StringLitType', 'Scalar'])).toEqual([
'scalar_foo', 'segment', 'generated_text'
]);
});
Expand Down
4 changes: 2 additions & 2 deletions lit_nlp/components/minimal_targeted_counterfactuals_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def spec(self) -> lit_types.Spec:
'size': lit_types.CategoryLabel(vocab=['small', 'medium', 'large']),
'weight': lit_types.Scalar(),
'legs': lit_types.Boolean(),
'description': lit_types.String(),
'description': lit_types.StringLitType(),
'animal': lit_types.CategoryLabel(vocab=ANIMALS),
}

Expand Down Expand Up @@ -90,7 +90,7 @@ def input_spec(self) -> lit_types.Spec:
'size': lit_types.CategoryLabel(vocab=['small', 'medium', 'large']),
'weight': lit_types.Scalar(),
'legs': lit_types.Boolean(),
'description': lit_types.String(),
'description': lit_types.StringLitType(),
}

def output_spec(self) -> lit_types.Spec:
Expand Down

0 comments on commit 72edd26

Please sign in to comment.