MCPcopy Create free account
hub / github.com/ipython/ipython / validate

Method validate

IPython/core/alias.py:136–160  ·  view source on GitHub ↗

Validate the alias, and return the number of arguments.

(self)

Source from the content-addressed store, hash-verified

134 self.nargs = self.validate()
135
136 def validate(self):
137 """Validate the alias, and return the number of arguments."""
138 if self.name in self.blacklist:
139 raise InvalidAliasError("The name %s can't be aliased "
140 "because it is a keyword or builtin." % self.name)
141 try:
142 caller = self.shell.magics_manager.magics['line'][self.name]
143 except KeyError:
144 pass
145 else:
146 if not isinstance(caller, Alias):
147 raise InvalidAliasError("The name %s can't be aliased "
148 "because it is another magic command." % self.name)
149
150 if not (isinstance(self.cmd, str)):
151 raise InvalidAliasError("An alias command must be a string, "
152 "got: %r" % self.cmd)
153
154 nargs = self.cmd.count('%s') - self.cmd.count('%%s')
155
156 if (nargs > 0) and (self.cmd.find('%l') >= 0):
157 raise InvalidAliasError('The %s and %l specifiers are mutually '
158 'exclusive in alias definitions.')
159
160 return nargs
161
162 def __repr__(self):
163 return "<alias {} for {!r}>".format(self.name, self.cmd)

Callers 1

__init__Method · 0.95

Calls 2

InvalidAliasErrorClass · 0.85
findMethod · 0.45

Tested by

no test coverage detected