py-algorand-sdk icon indicating copy to clipboard operation
py-algorand-sdk copied to clipboard

feat: runtime type checker created

Open Niraj-Kamdar opened this issue 4 years ago • 8 comments
trafficstars

relates: #179

Same method can be used for Transaction class to perform typecheck Let me know if you like the solution and would want me to make the other classes type safe.

Niraj-Kamdar avatar Jun 17 '21 15:06 Niraj-Kamdar

CLA assistant check
All committers have signed the CLA.

CLAassistant avatar Jun 17 '21 15:06 CLAassistant

Let me know which formatter are you guys using. I have used my default one for now.

Niraj-Kamdar avatar Jun 23 '21 16:06 Niraj-Kamdar

Unittests are working locally but I think there seems to be errors related to invalid types in integration tests. It seems like I have to go through CI log and change relevant test suite.

Niraj-Kamdar avatar Jun 24 '21 08:06 Niraj-Kamdar

There is bug in testing scripts:

FAILURE in step 'I build an application transaction with operation "create", application-id 0, sender "BH55E5RMBD4GYWXGX5W5PJ5JAHPGM5OXKDQH5DC4O2MGI7NW4H6VOE4CP4", approval-program "programs/loccheck.teal.tok", clear-program "programs/one.teal.tok", global-bytes 1, global-ints 0, local-bytes 1, local-ints 0, app-args "str:test", foreign-apps "5555,6666", foreign-assets "", app-accounts "", fee 1234, first-valid 9000, last-valid 9010, genesis-hash "Mf0h6zjkEIEZPtNM3zsrg+iHQFS0fZxhgr7w35I464M=", extra-pages 0':
  Feature:  Transaction fee test
  Scenario: App Call Fee Test -- @1.1 
Assertion Failed: expected type of approval_program: <class 'bytes'> but got <class 'bytearray'>
exception: expected type of approval_program: <class 'bytes'> but got <class 'bytearray'>

As mentioned in log approval_program should be bytes type but passed bytearray instead. It can be solved by typecasting to bytes but I don't know how to do it in .feature files.

An alternate solution can be auto typecasting in bytes

Niraj-Kamdar avatar Jun 24 '21 14:06 Niraj-Kamdar

@jasonpaulos Can you help here? Thanks!

michielmulders avatar Jun 24 '21 14:06 michielmulders

Any updates?

Niraj-Kamdar avatar Jun 27 '21 09:06 Niraj-Kamdar

Hi @Niraj-Kamdar, I apologize for the delay in reviewing. I believe we would be interested in this change if you could make TypeCheck into a function decorator instead of a base class, since then we could type check more than just __init__ methods.

Having it as a class has its own benefits. This will work for nested inheritance because of MRO and I think it's better than decorating every classes out there.

I can create a friendly decorator though if you want to type check a particular function.

Niraj-Kamdar avatar Jul 16 '21 04:07 Niraj-Kamdar

Is this technique usable when the argument types or not simple int, str, etc? Does isinstance(x, Union[int,str]) work?

Edit: It does. So I would prefer we avoid the change that made strs stop working in some of the constructors that accept a string or an int for an int parameter.

jannotti avatar Jan 22 '24 21:01 jannotti

Closing due to inactivity

jasonpaulos avatar Jun 05 '24 15:06 jasonpaulos