I’ve been exploring ways to reduce boilerplate in Python’s class syntax, and I would like to share a proposal for implicit self in instance methods, as a potential feature for Python 4.x.
Idea Summary:
Python currently requires all instance methods to explicitly declare self as the first parameter. While this is consistent and explicit, it can also be repetitive and adds syntactic overhead—especially for beginners or developers familiar with other OO languages where the instance is automatically inferred.
This proposal suggests allowing the self parameter to be implicitly injected by the interpreter if it’s omitted from method definitions. The change is fully backward compatible and intended for Python 4.x (major version).
Full Proposal:
I’ve prepared a detailed draft that includes:
Motivation and comparisons with Java, Kotlin, JS
Backward compatibility strategy
Examples with and without implicit self
Common criticisms and counterpoints
Migration and tooling considerations
You can read the full text here (formatted like a PEP):
Before considering turning this into a formal PEP, I’d love to hear your thoughts:
Is this directionally interesting for the future of Python?
What corner cases or problems might arise in practice?
Is it worth prototyping a @implicit_self decorator first?
This proposal does not reference any of the history of the discussion here and therefore does not address any of the issues of why self is currently explicit.
Also, if you would like to seriously propose this idea, your linked pre-PEP proposal appears very low quality (it gives strong written by AI vibes), have a look at the PEP submission process, read other PEPs that have proposed changes to the language, and at look at what they provided in order to justify changes.
I would suggest that in it’s current state that your proposal doesn’t bring anything novel to discuss, and therefore it is better to simply reference older discussions on this topic.
I don’t think there will be a Python 4, but if there was implicit self would probably be rejected as it was for Python 3.
PEP 3099 memorializes the decision and links to the discussion.
self will not become implicit.
Having self be explicit is a good thing. It makes the code clear by removing ambiguity about how a variable resolves. It also makes the difference between functions and methods small.
Hello DevDasher and welcome to the python community
Might I ask you a question: How experienced are you with python?
The reason for my question: I suppose that you are an experienced programmer, but new to python…?
As I started with python I had this “meh, why?” several times. But this phase goes over and within a short time I saw the “why”. So I’m wondering if you’re new to the party and are struggling with some new habits?
If this is the case you might give you some more time before you try to change python to the famous V4.0.
Apart from the issues already raised, your proposal makes multiple references to the “first parameter” as if it is somehow determinable whether the first parameter is supposed to be self, when in fact this is not the case. For instance you have:
Example — With Implicit self
class User:
def __init__(name):
self.name = name
def greet():
print(f"Hello, {self.name}!")
That __init__ does have a first parameter, which is name. Every method that has any (positional) parameters has a first parameter. The language does not require that a parameter intended to hold the instance be named self.