Skip to content

Decorator that enforces Type hints on functions (Python)

License

Notifications You must be signed in to change notification settings

Multivalence/enforceTypeHint

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 

Repository files navigation

Enforce Type Hints

Decorator that enforces Type hints on functions (Python)

Example Usage

Regular Functions

from enforceTH import enforceType

@enforceType
def doubler(x : int, y: int) -> int:
	value = x + y
	return value

print(doubler("Hello",3)) # Fails
print(doubler(3,3)) # Successful

Classes (self requires the "object" annotation)

from enforceTH import enforceType

class Person:

	@enforceType
	def __init__(self : object, name : str, age : int, job : str) -> None:
		self.name = name
		self.age = age
		self.job = job
	

	def giveName(self):
		return self.name
	
	def giveAge(self):
		return self.age
	
	def giveJob(self):
		return self.job


x = Test("John Doe",18,"Software Developer")
print(x.giveName())

About

Decorator that enforces Type hints on functions (Python)

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages