Skip to content

Comments

config: exclude multiple inheritance from JSON loading typing#4178

Merged
behrmann merged 1 commit intosystemd:mainfrom
behrmann:moretyping
Feb 18, 2026
Merged

config: exclude multiple inheritance from JSON loading typing#4178
behrmann merged 1 commit intosystemd:mainfrom
behrmann:moretyping

Conversation

@behrmann
Copy link
Contributor

As pointed out in [1], the reason that ty cannot infer that the assignment of the dict instance s to the dict j when loading JSON after checking that s is instance of dict, is because multiple inheritance is a thing and the passed in object could be a dict that doesn't have string keys, but does have a read method. So let's be explicit and disallow these unhandled cases. This also fixes that the order of these branches is not stable against reordering with pyright and type checking fails if e.g. the check for the read attribute is moved above the dict instance check.

[1] astral-sh/ty#1475 (comment)
[2] astral-sh/ty#1578

As pointed out in [1], the reason that ty cannot infer that the assignment of
the dict instance s to the dict j when loading JSON after checking that s is
instance of dict, is because multiple inheritance is a thing and the passed in
object could be a dict that doesn't have string keys, but does have a read
method. So let's be explicit and disallow these unhandled cases. This also
fixes that the order of these branches is not stable against reordering with
pyright and type checking fails if e.g. the check for the read attribute is
moved above the dict instance check.

[1] astral-sh/ty#1475 (comment)
[2] astral-sh/ty#1578
@behrmann behrmann merged commit 1388364 into systemd:main Feb 18, 2026
39 of 40 checks passed
@behrmann behrmann deleted the moretyping branch February 18, 2026 15:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants