MCPcopy Index your code
hub / github.com/ipython/ipython / validate

Method validate

IPython/core/alias.py:140–164  ·  view source on GitHub ↗

Validate the alias, and return the number of arguments.

(self)

Source from the content-addressed store, hash-verified

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