Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
208 views
in Technique[技术] by (71.8m points)

python - Allow chained method calls in certain orders only

I have a Python3 class that supports method chaining.

For example, I have methods a(), b() and c(). How can I allow c() to only be chained after a() or in another thought, how can I allow b() not to be chained next with function c()?

? a().b().c()
? b().c()
? a().c() #only allow this sequence

Is this possible?

Edit:

To define method chaining is self-explanatory in programming. It is basically calling methods in a chain.

method_a().method_b().method_c()

Class Structure

class Test:
   def a(self):
      ...
      return self

   def b(self):
      ...
      return self

   def c(self):
      ...
      return self
question from:https://stackoverflow.com/questions/65830337/allow-chained-method-calls-in-certain-orders-only

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...