MCPcopy Index your code
hub / github.com/python/cpython / __repr__

Method __repr__

Lib/tkinter/__init__.py:264–300  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

262 """
263
264 def __repr__(self):
265 attrs = {k: v for k, v in self.__dict__.items() if v != '??'}
266 if not self.char:
267 del attrs['char']
268 elif self.char != '??':
269 attrs['char'] = repr(self.char)
270 if not getattr(self, 'send_event', True):
271 del attrs['send_event']
272 if self.state == 0:
273 del attrs['state']
274 elif isinstance(self.state, int):
275 state = self.state
276 mods = ('Shift', 'Lock', 'Control',
277 'Mod1', 'Mod2', 'Mod3', 'Mod4', 'Mod5',
278 'Button1', 'Button2', 'Button3', 'Button4', 'Button5')
279 s = []
280 for i, n in enumerate(mods):
281 if state & (1 << i):
282 s.append(n)
283 state = state & ~((1<< len(mods)) - 1)
284 if state or not s:
285 s.append(hex(state))
286 attrs['state'] = '|'.join(s)
287 if self.delta == 0:
288 del attrs['delta']
289 # widget usually is known
290 # serial and time are not very interesting
291 # keysym_num duplicates keysym
292 # x_root and y_root mostly duplicate x and y
293 keys = ('send_event',
294 'state', 'keysym', 'keycode', 'char',
295 'num', 'delta', 'focus',
296 'x', 'y', 'width', 'height')
297 return '<%s event%s>' % (
298 getattr(self.type, 'name', self.type),
299 ''.join(' %s=%s' % (k, attrs[k]) for k in keys if k in attrs)
300 )
301
302 __class_getitem__ = classmethod(types.GenericAlias)
303

Callers

nothing calls this directly

Calls 4

enumerateFunction · 0.85
itemsMethod · 0.45
appendMethod · 0.45
joinMethod · 0.45

Tested by

no test coverage detected