Do you know how `self` gets injected into a method in Python?

Methods defined in a class are function objects.

Methods in a class instance are **bound methods**

A thread 👇
#100DaysOfCode #freeCodeCamp  import logging from datacl...
A function object is implemented as a descriptor.

Which means when we access its value we are calling the __get__method in the function object.

👇  A method in an instance is...
When you call a method in an object instance the function descriptor injects the instance as the first argument.

In fact, we can manually call the descriptor from the class definition to show how it's actually being called:

👇 And, we can double check th...
You can play around with this notebook:mybinder.org/v2/gh/rmcomple…

A thread about descriptors:

Python docs about descriptors: docs.python.org/3/howto/descri…

• • •

Missing some Tweet in this thread? You can try to force a refresh
 

Keep Current with Josue🧪

Josue🧪 Profile picture

Stay in touch and get notified when new unrolls are available from this author!

Read all threads

This Thread may be Removed Anytime!

PDF

Twitter may remove this content at anytime! Save it as PDF for later use!

Try unrolling a thread yourself!

how to unroll video
  1. Follow @ThreadReaderApp to mention us!

  2. From a Twitter thread mention us with a keyword "unroll"
@threadreaderapp unroll

Practice here first or read more on our help page!

More from @rmcomplexity

10 Jan
Do you know what Python descriptors are?

Descriptor is a protocol in python that enables data to have a saying about what happens on lookup, storage and deletion.

A great use case for descriptors are data validation.

#100DaysOfCode #freeCodeCamp

🧵👇
When a class defines `__get__`, `__set__` or `__delete__` it becomes a descriptor and is called with the `.` (dot) operator.

By implementing validators as descriptors we push everything validation-related outside the class that holds data.
👇
Let's define two validators as descriptors.

They both store the actual value assigned in a private variable and run a validation function when a value is assigned.

Let's go over the special methods implemented 👇 class SkuValidator:     &qu...class PositiveIntValidator:...
Read 13 tweets
30 Nov 20
👩‍🏫 Are you mentoring?
🧑‍🎓Do you have a mentor?

Teaching others reinforces what you know!

A mentor can help you identify the things you need to work on to become better at your job

7 key things about finding a mentor and being a mentor

🧵👇
1⃣What is a mentor?

A person who help you improve professionally and personally

Sometimes is someone with whom you can have an honest conversation about anything

In a Mentor - Mentee relationship both parties benefit. But as a mentee always be respectful of your mentor's time.
2⃣How do I find a mentor?

You first have to show interest in growing and you have to be patient

Find people with experience in the fields you want to grow and make yourself noticed

You can contribute to some body else's work, ask questions or volunteer

Remember to be patient
Read 8 tweets

Did Thread Reader help you today?

Support us! We are indie developers!


This site is made by just two indie developers on a laptop doing marketing, support and development! Read more about the story.

Become a Premium Member ($3/month or $30/year) and get exclusive features!

Become Premium

Too expensive? Make a small donation by buying us coffee ($5) or help with server cost ($10)

Donate via Paypal Become our Patreon

Thank you for your support!

Follow Us on Twitter!