Skip to content

Python: Port ContainsNonContainer.ql#21680

Draft
tausbn wants to merge 3 commits intomainfrom
tausbn/python-port-contains-non-container
Draft

Python: Port ContainsNonContainer.ql#21680
tausbn wants to merge 3 commits intomainfrom
tausbn/python-port-contains-non-container

Conversation

@tausbn
Copy link
Copy Markdown
Contributor

@tausbn tausbn commented Apr 9, 2026

Uses the new DuckTyping module to handle recognising whether a class is a container or not. Only trivial test changes (one version uses "class", the other "Class").

Note that the ported query has no understanding of built-in classes. At some point we'll likely want to replace hasUnresolvedBase (which will hold for any class that extends a built-in) with something that's aware of the built-in classes.

tausbn added 2 commits April 8, 2026 12:18
Uses the new `DuckTyping` module to handle recognising whether a class
is a container or not. Only trivial test changes (one version uses
"class", the other "Class").

Note that the ported query has no understanding of built-in classes. At
some point we'll likely want to replace `hasUnresolvedBase` (which will
hold for any class that extends a built-in) with something that's aware
of the built-in classes.
First fix handles the case where there's interference from a class-based
decorator on a function. In this case, _technically_ we have an instance
of the decorator class, but in practice this decorator will (hopefully)
forward all accesses to the thing it wraps.

The second fix has to do with methods that are added dynamically using
`setattr`. In this case, we cannot be sure that the relevant methods are
actually missing.
@tausbn tausbn added the no-change-note-required This PR does not need a change note label Apr 9, 2026
@github-actions github-actions bot added the Python label Apr 9, 2026
Eliminates cases where we explicitly check whether the object in
question is an instance of (a subclass of) a built-in container type.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

no-change-note-required This PR does not need a change note Python

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant