config: exclude multiple inheritance from JSON loading typing#4178
Merged
behrmann merged 1 commit intosystemd:mainfrom Feb 18, 2026
Merged
config: exclude multiple inheritance from JSON loading typing#4178behrmann merged 1 commit intosystemd:mainfrom
behrmann merged 1 commit intosystemd:mainfrom
Conversation
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
daandemeyer
approved these changes
Feb 18, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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