Created
July 7, 2020 15:19
-
-
Save attashe/8f3b62a39887849d94a2c60fcb2e7727 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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