cspwizard commented on code in PR #2523:
URL: https://github.com/apache/thrift/pull/2523#discussion_r842099713
##########
compiler/cpp/src/thrift/generate/t_py_generator.cc:
##########
@@ -2497,6 +2513,11 @@ void t_py_generator::generate_serialize_field(ostream&
out, t_field* tfield, str
* @param prefix String prefix to attach to all fields
*/
void t_py_generator::generate_serialize_struct(ostream& out, t_struct*
tstruct, string prefix) {
+ if(gen_type_hints_) {
+ indent(out) << "if not type(" << prefix << ") is " <<
type_to_py_type(tstruct)
Review Comment:
you are right duck typing wouldn't work, but I think it worse it. As this
keeps the contract consistent. For example we have structs like this:
```
struct Date {
1: i32 days_since_AD1
}
struct License {
1: string code
2: string name
3: Date date
}
```
in case if we don't have this check we could set anything that have write
method to the `date` field and probably it would be able to serialize, but when
this message would be deserialized deserizer would fail (in the best case
scenario) in the worst and most common there would be some unusable garbage in
the data.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]