MCPcopy Create free account
hub / github.com/ScottfreeLLC/AlphaPy / __new__

Method __new__

alphapy/variables.py:109–131  ·  view source on GitHub ↗
(cls,
                name,
                expr,
                replace = False)

Source from the content-addressed store, hash-verified

107 # function __new__
108
109 def __new__(cls,
110 name,
111 expr,
112 replace = False):
113 # code
114 efound = expr in [Variable.variables[key].expr for key in Variable.variables]
115 if efound:
116 key = [key for key in Variable.variables if expr in Variable.variables[key].expr]
117 logger.info("Expression '%s' already exists for key %s", expr, key)
118 return
119 else:
120 if replace or not name in Variable.variables:
121 if not valid_name(name):
122 logger.info("Invalid variable key: %s", name)
123 return
124 try:
125 result = parser.expr(expr)
126 except:
127 logger.info("Invalid expression: %s", expr)
128 return
129 return super(Variable, cls).__new__(cls)
130 else:
131 logger.info("Key %s already exists", name)
132
133 # function __init__
134

Callers

nothing calls this directly

Calls 1

valid_nameFunction · 0.90

Tested by

no test coverage detected