4

According to Python documentation, implementing a class in C for Python can be roughly divided into three steps:

  1. defining the Object (the data impl)
  2. defining the Type (the behavior wrapper)
  3. defining concrete behaviors, and set them into corresponding tp_xx slots

For new function, init function, instance members, attributes, and even dealloc, all of them can be found a slot in PyTypeObject declaration, like tp_new, tp_init, tp_members, tp_methods and tp_dealloc. But there is not a slot like tp_statics.

Where should I declare the static variables and where should I set them up? I searched for the internet but got nothing. Could anyone give me a clue about this?

0x51ba
  • 463
  • 3
  • 12
John
  • 65
  • 1
  • 6

2 Answers2

1

Maybe you should check out this question.

There is no static keyword in Python, class attributes are stored in class.__dict__.

sup
  • 323
  • 1
  • 12
0

@avram has mentioned an answer which solved my problem.
But for anyone who found that your static attributes does not get updated after modification, you may check PyType_Modified function.

John
  • 65
  • 1
  • 6