Skip to main content

Lib to verify types of functions

Project description

Verify types

Verifica a tipagem e os retornos das funções em python

How works ?

pip3 install verify-types

After that how use ?

To use in one method you only need the decorator validate_params

from verify_types import validate_params


@validate_params
def example(a: str, b: float) -> str:
	return f"a: {b}"

To this case is possible verify if the input and output is correct. If dont't match the types a ValueError will raise with correct type, actual type and path of an error.

To use on all class's methods

from verify_types import validate_params, decorate_all_methods                  
                                                                                
                                                                                
@decorate_all_methods(validate_params)                                          
class TestA:                                                                    
    def __init__(self, a: str) -> None:                                         
        self.a = a                                                              
                                                                                
    def print_a(self) -> None:                                                  
        print(self.a)                                                           
                                                                                
    def concat_a(self, b: str) -> str:                                          
        return self.a + b                                                       
                                                                                
    def run(self) -> None:                                                      
        self.print_a()                                                          
        print(self.concat_a("nossa"))                                           
                                                                                
                                                                                
if __name__ == "__main__":                                                      
    test = TestA("Nossa")                                                       
    test.run()

This will be decorate all class methods

Observetion

If you use the decorator You must use type hint or and error will raise.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

verify_types-1.0.5.tar.gz (4.0 kB view hashes)

Uploaded Source

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page