MCPcopy Index your code
hub / github.com/RustPython/RustPython / Class

Class Class

Lib/symtable.py:233–280  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

231
232
233class Class(SymbolTable):
234
235 __methods = None
236
237 def get_methods(self):
238 """Return a tuple of methods declared in the class.
239 """
240 import warnings
241 typename = f'{self.__class__.__module__}.{self.__class__.__name__}'
242 warnings.warn(f'{typename}.get_methods() is deprecated '
243 f'and will be removed in Python 3.16.',
244 DeprecationWarning, stacklevel=2)
245
246 if self.__methods is None:
247 d = {}
248
249 def is_local_symbol(ident):
250 flags = self._table.symbols.get(ident, 0)
251 return ((flags >> SCOPE_OFF) & SCOPE_MASK) == LOCAL
252
253 for st in self._table.children:
254 # pick the function-like symbols that are local identifiers
255 if is_local_symbol(st.name):
256 match st.type:
257 case _symtable.TYPE_FUNCTION:
258 # generators are of type TYPE_FUNCTION with a ".0"
259 # parameter as a first parameter (which makes them
260 # distinguishable from a function named 'genexpr')
261 if st.name == 'genexpr' and '.0' in st.varnames:
262 continue
263 d[st.name] = 1
264 case _symtable.TYPE_TYPE_PARAMETERS:
265 # Get the function-def block in the annotation
266 # scope 'st' with the same identifier, if any.
267 scope_name = st.name
268 for c in st.children:
269 if c.name == scope_name and c.type == _symtable.TYPE_FUNCTION:
270 # A generic generator of type TYPE_FUNCTION
271 # cannot be a direct child of 'st' (but it
272 # can be a descendant), e.g.:
273 #
274 # class A:
275 # type genexpr[genexpr] = (x for x in [])
276 assert scope_name != 'genexpr' or '.0' not in c.varnames
277 d[scope_name] = 1
278 break
279 self.__methods = tuple(d)
280 return self.__methods
281
282
283class Symbol:

Callers 1

newMethod · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected