Skip to content

Fix enum stub definitions - #2447

Closed
jorenham wants to merge 1 commit into
PyAV-Org:masterfrom
jorenham:typing/fix-enum-stubs
Closed

jorenham wants to merge 1 commit into
PyAV-Org:masterfrom
jorenham:typing/fix-enum-stubs

Conversation

@jorenham

@jorenham jorenham commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

I noticed that the Enum and Flag declarations in the .pyi stubs weren't quite right. I changed them in a backwards compatible manner so that they now follow conform to the typing spec.

I verified with stubtest (a mypy tool) that this doesn't result in new errors (it went down by 2 even because of the removed __get__ and __set__). I plan to take care of the remaining (265) stubtest errors as well (assuming you're open to it).

@WyattBlue

Copy link
Copy Markdown
Member

This is not a 'fix'. This is - at best - applying a new best practice which could change in the future.

@jorenham

Copy link
Copy Markdown
Contributor Author

applying a new best practice

The typing spec is not a "best practice", it's the official definition of Python's type system, and every single type-checkers has it has their goal to conform to this typing spec.


which could change in the future.

The Python Typing Council (which I'm part of) takes extreme care not to introduce backwards incompatible changes in Python's official typing spec.

In fact, it's the other way around: The current situation is that these stubs are relying on undefined behavior. It's surprising that this even works TBH. There's a good chance though that it only works with certain type-checkers like mypy. And since this behavior isn't (and won't be) specified in the typing spec, there's a good change that this will break in the future.

As far as I can tell there's also no good reason to choose the current exotic (and very verbose) cast + ClassVar style, over the conventional and officially supported declarations from this PR. So maybe I'm missing something, but I just don't see any reason for closing this.

Anyway, of course it's your decision to make, but I think it's a mistake not to accept this.

@WyattBlue WyattBlue reopened this Oct 24, 2026
@WyattBlue WyattBlue closed this Oct 24, 2026
@WyattBlue

Copy link
Copy Markdown
Member

I think I'm going to apply these changes -- just split between multiple commits so it's easier to follow

@jorenham

Copy link
Copy Markdown
Contributor Author

Much appreciated :)

@jorenham
jorenham deleted the typing/fix-enum-stubs branch October 24, 2026 21:09
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