소스 검색

added some convenience class methods

Dimitri Korsch 3 년 전
부모
커밋
03497c1563
1개의 변경된 파일14개의 추가작업 그리고 0개의 파일을 삭제
  1. 14 0
      cvargparse/argument.py

+ 14 - 0
cvargparse/argument.py

@@ -5,6 +5,20 @@ class Argument(object):
 		self.args = args # positional arugments
 		self.kw = kw # keyword arguments
 
+	@classmethod
+	def int(cls, *args, **kw):
+		arg_type = kw.pop("type", int)
+		return cls(*args, type=arg_type, **kw)
+
+	@classmethod
+	def float(cls, *args, **kw):
+		arg_type = kw.pop("type", float)
+		return cls(*args, type=arg_type, **kw)
+
+	@classmethod
+	def flag(cls, *args, **kw):
+		action = kw.pop("action", "store_true")
+		return cls(*args, action=action, **kw)
 
 class FileArgument(Argument):
 	def __init__(self, *args, **kw):