KEMBAR78
Remove `@final` from subclassesable types by sobolevn · Pull Request #8544 · python/typeshed · GitHub
Skip to content

Conversation

@sobolevn
Copy link
Member

I indentified that these types can be subclassed:

>>> from collections import _OrderedDictItemsView, _OrderedDictKeysView, _OrderedDictValuesView
>>> class A(_OrderedDictItemsView): ...
... 
>>> class B(_OrderedDictKeysView): ...
... 
>>> class C(_OrderedDictValuesView): ...
... 

Right now our stubtest does not check @final declaration on regular types. Maybe we should?

@AlexWaygood
Copy link
Member

AlexWaygood commented Aug 16, 2022

>>> from collections import OrderedDict
>>> class Foo(type(OrderedDict({'foo': 'bar'}).keys())): ...
...
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: type 'odict_keys' is not an acceptable base type

The C implementation that's actually used for OrderedDict.keys() at runtime differs from the pure-Python implementation that's exposed as collections._OrderedDictKeysView. This has come up before; it might be good to add a comment about it to the stub. Or alternatively, maybe we should change OrderedDict so that .keys() doesn't return _OrderedDictKeysView, but returns odict_keys or something. But that seems a bit weird, especially since this is the only way I know of in which the pure-Python implementations and the C implementations of these classes differ.

Right now our stubtest does not check @final declaration on regular types. Maybe we should?

This was considered in python/mypy#12091, but rejected due to zero true positives and several false-positives (with the collections hits being considered as false-positives): python/mypy#12091 (comment).

@github-actions

This comment has been minimized.

1 similar comment
@github-actions
Copy link
Contributor

According to mypy_primer, this change has no effect on the checked open source code. 🤖🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants