Skip to content

Instantly share code, notes, and snippets.

@attashe
Created July 7, 2020 15:19
Show Gist options
  • Save attashe/8f3b62a39887849d94a2c60fcb2e7727 to your computer and use it in GitHub Desktop.
Save attashe/8f3b62a39887849d94a2c60fcb2e7727 to your computer and use it in GitHub Desktop.
import argparse
class ConfigType(type):
def __new__(mcls, name, bases, attrs):
if name.startswith('None'):
return None
print(attrs)
mcls.parse_args()
newattrs = {}
for attrname, attrvalue in attrs.items():
if not attrname.startswith('__'):
newattrs[attrname] = getattr(mcls.args, attrname)
return super(ConfigType, mcls).__new__(mcls, name, bases, newattrs)
def __init__(self, name, bases, attrs):
super(ConfigType, self).__init__(name, bases, attrs)
# classregistry.register(self, self.interfaces)
print("Would register class %s now." % self)
@classmethod
def add(cls, *args, **kwargs):
print('Add to argparse')
cls.parser.add_argument(*args, **kwargs)
@classmethod
def parse_args(cls):
# ConfigType.build_parser()
cls.args = cls.parser.parse_args()
def __getattr__(self, attr):
print(attr)
return attr
parser = argparse.ArgumentParser()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment