Skip to content

Commit

Permalink
Step 1: Add an annotation MigrationBlockingAllowInheritance to the py…
Browse files Browse the repository at this point in the history
…thon annotations:

Summary: Add an annotation `MigrationBlockingAllowInheritance` to the python annotations

Reviewed By: ahilger

Differential Revision: D68361912

fbshipit-source-id: b54739b3ef6243a7d6fcb0b24847cb9fadc2a690
  • Loading branch information
Danfeng Wang authored and facebook-github-bot committed Jan 22, 2025
1 parent 426f638 commit 7b55a11
Show file tree
Hide file tree
Showing 30 changed files with 1,313 additions and 6 deletions.
3 changes: 3 additions & 0 deletions third-party/thrift/src/thrift/annotation/python.thrift
Original file line number Diff line number Diff line change
Expand Up @@ -100,3 +100,6 @@ struct UseCAPI {
/// It is only available for typedefs that resolve to binary, string, and container type.
@scope.Typedef
struct Py3EnableCppAdapter {}

@scope.Structured
struct MigrationBlockingAllowInheritance {}
2 changes: 2 additions & 0 deletions third-party/thrift/src/thrift/compiler/ast/uri.h
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,8 @@ inline constexpr auto kPythonUseCAPIUri =
"facebook.com/thrift/annotation/python/UseCAPI";
inline constexpr auto kPythonPy3EnableCppAdapterUri =
"facebook.com/thrift/annotation/python/Py3EnableCppAdapter";
inline constexpr auto kPythonMigrationBlockingAllowInheritanceUri =
"facebook.com/thrift/annotation/python/MigrationBlockingAllowInheritance";

// Hack:
inline constexpr auto kHackAdapterUri =
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
/**
* Autogenerated by Thrift
*
* DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
* @generated
*/
package com.facebook.thrift.annotation.python_deprecated;

import java.util.List;
import java.util.ArrayList;
import java.util.Map;
import java.util.HashMap;
import java.util.Set;
import java.util.HashSet;
import java.util.Collections;
import java.util.BitSet;
import java.util.Arrays;
import com.facebook.thrift.*;
import com.facebook.thrift.annotations.*;
import com.facebook.thrift.async.*;
import com.facebook.thrift.meta_data.*;
import com.facebook.thrift.server.*;
import com.facebook.thrift.transport.*;
import com.facebook.thrift.protocol.*;

@SuppressWarnings({ "unused", "serial" })
public class MigrationBlockingAllowInheritance implements TBase, java.io.Serializable, Cloneable {
private static final TStruct STRUCT_DESC = new TStruct("MigrationBlockingAllowInheritance");


public MigrationBlockingAllowInheritance() {
}

/**
* Performs a deep copy on <i>other</i>.
*/
public MigrationBlockingAllowInheritance(MigrationBlockingAllowInheritance other) {
}

public MigrationBlockingAllowInheritance deepCopy() {
return new MigrationBlockingAllowInheritance(this);
}

@Override
public boolean equals(Object _that) {
if (_that == null)
return false;
if (this == _that)
return true;
if (!(_that instanceof MigrationBlockingAllowInheritance))
return false;
MigrationBlockingAllowInheritance that = (MigrationBlockingAllowInheritance)_that;

return true;
}

@Override
public int hashCode() {
return Arrays.deepHashCode(new Object[] {});
}

// This is required to satisfy the TBase interface, but can't be implemented on immutable struture.
public void read(TProtocol iprot) throws TException {
throw new TException("unimplemented in android immutable structure");
}

public static MigrationBlockingAllowInheritance deserialize(TProtocol iprot) throws TException {
TField __field;
iprot.readStructBegin();
while (true)
{
__field = iprot.readFieldBegin();
if (__field.type == TType.STOP) {
break;
}
switch (__field.id)
{
default:
TProtocolUtil.skip(iprot, __field.type);
break;
}
iprot.readFieldEnd();
}
iprot.readStructEnd();

MigrationBlockingAllowInheritance _that;
_that = new MigrationBlockingAllowInheritance(
);
_that.validate();
return _that;
}

public void write(TProtocol oprot) throws TException {
validate();

oprot.writeStructBegin(STRUCT_DESC);
oprot.writeFieldStop();
oprot.writeStructEnd();
}

@Override
public String toString() {
return toString(1, true);
}

@Override
public String toString(int indent, boolean prettyPrint) {
return TBaseHelper.toStringHelper(this, indent, prettyPrint);
}

public void validate() throws TException {
// check for required fields
}

}

Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,17 @@ var (
NewFunc: func() thrift.Struct { return NewPy3EnableCppAdapter() },
},

}
}()
premadeCodecTypeSpec_python_MigrationBlockingAllowInheritance = func() *thrift.TypeSpec {
return &thrift.TypeSpec{
FullName: "python.MigrationBlockingAllowInheritance",
CodecStructSpec: &thrift.CodecStructSpec{
ScopedName: "python.MigrationBlockingAllowInheritance",
IsUnion: false,
NewFunc: func() thrift.Struct { return NewMigrationBlockingAllowInheritance() },
},

}
}()
)
Expand Down Expand Up @@ -260,6 +271,20 @@ var (
},
FieldSpecNameToIndex: map[string]int{
},
}
}()
premadeStructSpec_MigrationBlockingAllowInheritance = func() *thrift.StructSpec {
return &thrift.StructSpec{
Name: "MigrationBlockingAllowInheritance",
ScopedName: "python.MigrationBlockingAllowInheritance",
IsUnion: false,
IsException: false,
FieldSpecs: []thrift.FieldSpec{
},
FieldSpecIDToIndex: map[int16]int{
},
FieldSpecNameToIndex: map[string]int{
},
}
}()
)
Expand All @@ -274,6 +299,7 @@ var premadeStructSpecs = func() []*thrift.StructSpec {
fbthriftResults = append(fbthriftResults, premadeStructSpec_Adapter)
fbthriftResults = append(fbthriftResults, premadeStructSpec_UseCAPI)
fbthriftResults = append(fbthriftResults, premadeStructSpec_Py3EnableCppAdapter)
fbthriftResults = append(fbthriftResults, premadeStructSpec_MigrationBlockingAllowInheritance)
return fbthriftResults
}()

Expand All @@ -288,6 +314,7 @@ var premadeCodecSpecsMap = func() map[string]*thrift.TypeSpec {
fbthriftTypeSpecsMap[premadeCodecTypeSpec_bool.FullName] = premadeCodecTypeSpec_bool
fbthriftTypeSpecsMap[premadeCodecTypeSpec_python_UseCAPI.FullName] = premadeCodecTypeSpec_python_UseCAPI
fbthriftTypeSpecsMap[premadeCodecTypeSpec_python_Py3EnableCppAdapter.FullName] = premadeCodecTypeSpec_python_Py3EnableCppAdapter
fbthriftTypeSpecsMap[premadeCodecTypeSpec_python_MigrationBlockingAllowInheritance.FullName] = premadeCodecTypeSpec_python_MigrationBlockingAllowInheritance
return fbthriftTypeSpecsMap
}()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,12 @@ var (
SetName("python.Py3EnableCppAdapter"),
)
}()
premadeThriftType_python_MigrationBlockingAllowInheritance = func() *metadata.ThriftType {
return metadata.NewThriftType().SetTStruct(
metadata.NewThriftStructType().
SetName("python.MigrationBlockingAllowInheritance"),
)
}()
)

// Helper type to allow us to store Thrift types in a slice at compile time,
Expand All @@ -92,6 +98,7 @@ var premadeThriftTypesMap = func() map[string]*metadata.ThriftType {
thriftTypesWithFullName = append(thriftTypesWithFullName, thriftTypeWithFullName{ "bool", premadeThriftType_bool })
thriftTypesWithFullName = append(thriftTypesWithFullName, thriftTypeWithFullName{ "python.UseCAPI", premadeThriftType_python_UseCAPI })
thriftTypesWithFullName = append(thriftTypesWithFullName, thriftTypeWithFullName{ "python.Py3EnableCppAdapter", premadeThriftType_python_Py3EnableCppAdapter })
thriftTypesWithFullName = append(thriftTypesWithFullName, thriftTypeWithFullName{ "python.MigrationBlockingAllowInheritance", premadeThriftType_python_MigrationBlockingAllowInheritance })

fbthriftThriftTypesMap := make(map[string]*metadata.ThriftType, len(thriftTypesWithFullName))
for _, value := range thriftTypesWithFullName {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -756,6 +756,78 @@ func (x *Py3EnableCppAdapter) setDefaults() *Py3EnableCppAdapter {
return x
}

type MigrationBlockingAllowInheritance struct {
}
// Compile time interface enforcer
var _ thrift.Struct = (*MigrationBlockingAllowInheritance)(nil)

func NewMigrationBlockingAllowInheritance() *MigrationBlockingAllowInheritance {
return (&MigrationBlockingAllowInheritance{}).setDefaults()
}



func (x *MigrationBlockingAllowInheritance) Write(p thrift.Encoder) error {
if err := p.WriteStructBegin("MigrationBlockingAllowInheritance"); err != nil {
return thrift.PrependError(fmt.Sprintf("%T write struct begin error: ", x), err)
}


if err := p.WriteFieldStop(); err != nil {
return thrift.PrependError(fmt.Sprintf("%T write field stop error: ", x), err)
}

if err := p.WriteStructEnd(); err != nil {
return thrift.PrependError(fmt.Sprintf("%T write struct end error: ", x), err)
}
return nil
}

func (x *MigrationBlockingAllowInheritance) Read(p thrift.Decoder) error {
if _, err := p.ReadStructBegin(); err != nil {
return thrift.PrependError(fmt.Sprintf("%T read error: ", x), err)
}

for {
fieldName, wireType, id, err := p.ReadFieldBegin()
if err != nil {
return thrift.PrependError(fmt.Sprintf("%T field %d ('%s') read error: ", x, id, fieldName), err)
}

if wireType == thrift.STOP {
break;
}

var fieldReadErr error
switch {
default:
fieldReadErr = p.Skip(wireType)
}

if fieldReadErr != nil {
return fieldReadErr
}

if err := p.ReadFieldEnd(); err != nil {
return err
}
}

if err := p.ReadStructEnd(); err != nil {
return thrift.PrependError(fmt.Sprintf("%T read struct end error: ", x), err)
}

return nil
}

func (x *MigrationBlockingAllowInheritance) String() string {
return thrift.StructToString(reflect.ValueOf(x))
}

func (x *MigrationBlockingAllowInheritance) setDefaults() *MigrationBlockingAllowInheritance {
return x
}



// RegisterTypes registers types found in this file that have a thrift_uri with the passed in registry.
Expand All @@ -769,5 +841,6 @@ func RegisterTypes(registry interface {
registry.RegisterType("facebook.com/thrift/annotation/python/Adapter", func() any { return NewAdapter() })
registry.RegisterType("facebook.com/thrift/annotation/python/UseCAPI", func() any { return NewUseCAPI() })
registry.RegisterType("facebook.com/thrift/annotation/python/Py3EnableCppAdapter", func() any { return NewPy3EnableCppAdapter() })
registry.RegisterType("facebook.com/thrift/annotation/python/MigrationBlockingAllowInheritance", func() any { return NewMigrationBlockingAllowInheritance() })

}
Original file line number Diff line number Diff line change
Expand Up @@ -798,3 +798,85 @@ public function readFromJson(string $jsonText): void {

}

/**
* Original thrift struct:-
* MigrationBlockingAllowInheritance
*/
<<\ThriftTypeInfo(shape('uri' => 'facebook.com/thrift/annotation/python/MigrationBlockingAllowInheritance'))>>
class MigrationBlockingAllowInheritance implements \IThriftSyncStruct, \IThriftStructMetadata, \IThriftShapishSyncStruct {
use \ThriftSerializationTrait;

const \ThriftStructTypes::TSpec SPEC = dict[
];
const dict<string, int> FIELDMAP = dict[
];

const type TConstructorShape = shape(
);

const type TShape = shape(
);
const int STRUCTURAL_ID = 957977401221134810;

public function __construct()[] {
}

public static function withDefaultValues()[]: this {
return new static();
}

public static function fromShape(self::TConstructorShape $shape)[]: this {
return new static(
);
}

public function getName()[]: string {
return 'MigrationBlockingAllowInheritance';
}

public static function getStructMetadata()[]: \tmeta_ThriftStruct {
return \tmeta_ThriftStruct::fromShape(
shape(
"name" => "python.MigrationBlockingAllowInheritance",
"is_union" => false,
)
);
}

public static function getAllStructuredAnnotations()[write_props]: \TStructAnnotations {
return shape(
'struct' => dict[
'\facebook\thrift\annotation\Structured' => \facebook\thrift\annotation\Structured::fromShape(
shape(
)
),
],
'fields' => dict[
],
);
}

public static function __fromShape(self::TShape $shape)[]: this {
return new static(
);
}

public function __toShape()[]: self::TShape {
return shape(
);
}
public function getInstanceKey()[write_props]: string {
return \TCompactSerializer::serialize($this);
}

public function readFromJson(string $jsonText): void {
$parsed = json_decode($jsonText, true);

if ($parsed === null || !($parsed is KeyedContainer<_, _>)) {
throw new \TProtocolException("Cannot parse the given json string.");
}

}

}

Loading

0 comments on commit 7b55a11

Please sign in to comment.