# Disallow access to class variables with Self

**URL:** <https://discuss.python.org/t/disallow-access-to-class-variables-with-self/105434>\
**Category:** Typing\
**Created:** [December 28, 2025, 1:10am UTC](https://discuss.python.org/t/disallow-access-to-class-variables-with-self/105434 "2025-12-28T01:10:17Z")\
**Posts on this page:** 1\
**Showing post:** 8

<div class="post-metadata">

**Author:** ![carljm](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/carljm/32/959_2.png) [@carljm](https://discuss.python.org/u/carljm)\
**Post date:** [January 13, 2026, 11:12pm UTC](https://discuss.python.org/t/disallow-access-to-class-variables-with-self/105434/8 "2026-01-13T23:12:13Z")

</div>

How special is class access here? It’s unsafe to ever inherit a mutable attribute containing `Self`, even if access only ever happens on instances:

```python
class Parent:
    x: list[Self]

class Child(Parent):
    pass

def f(p: Parent):
    p.x.append(Parent())

c = Child()
f(c)
# no type errors above, but now c.x contains a Parent instance

```

I think this is what @mikeshardmind was referring to above.

I think it is hard to phrase this restriction partly because the fully coherent restriction would be phrased in terms of Liskov restrictions on inheritance in general and variance of `Self` types, not in terms of limitations on what you can access via a class.

---

_[View the full topic](https://discuss.python.org/t/disallow-access-to-class-variables-with-self/105434)._
