Skip to content

feat: export FilterReturn from weaviate.classes.query#1993

Merged
tsmith023 merged 2 commits intoweaviate:mainfrom
renaudcepre:fix/export-public-filter-return-type
Mar 24, 2026
Merged

feat: export FilterReturn from weaviate.classes.query#1993
tsmith023 merged 2 commits intoweaviate:mainfrom
renaudcepre:fix/export-public-filter-return-type

Conversation

@renaudcepre
Copy link
Contributor

Context

Apologies for not opening an issue first, this felt like a small enough change to propose directly and discuss on the code itself !

Problem

Filter.by_property().equal() and similar builder methods return _Filters / _FilterValue, which are private types from weaviate.collections.classes.filters

However, collection methods like fetch_objects(filters=...), query.hybrid(...), etc. accept Optional[_Filters] as the type for the filters parameter.

This makes it impossible to correctly type-annotate user code without importing a private type:

from weaviate.collections.classes.filters import _Filters  # private!

def my_function(filters: _Filters) -> None:
    collection.query.fetch_objects(filters=filters)

In pyright strict mode (reportPrivateUsage: error), this is flagged as an error.

Solution

A FilterReturn: TypeAlias = _Filters already existed in weaviate.collections.classes.filters but was never re-exported publicly.

This PR:

  1. Re-exports FilterReturn from weaviate.classes.query (alongside Filter)
  2. Replaces all internal usage of _Filters with FilterReturn in executors, stubs, and internal modules
  3. Regenerates .pyi stubs via tools/stubs_regen.sh

Users can now write:

from weaviate.classes.query import Filter, FilterReturn

def search(filters: FilterReturn | None = None) -> None:
    collection.query.fetch_objects(filters=filters)  # clean, no private types

Verification

pyright strict (reportPrivateUsage: error):

  • Before: 1 error: "_Filters" is private and used outside of the module in which it is declared
  • After: 0 errors, 0 warnings

Unit tests: 324 passed

Scope

There are other private types in public signatures (_GenerativeConfigRuntime, _RerankerProvider, _ShardingConfigCreate, etc.) that have the same issue. This PR intentionally focuses on FilterReturn only to keep the diff reviewable. Happy to open a follow-up issue or PR for the others if this approach looks good.

Replace private _Filters usage with the existing public FilterReturn
type alias across all executors, stubs, and internal modules.

This allows users to type-annotate filter parameters without importing
private types, resolving pyright reportPrivateUsage errors in strict mode.
Copy link

@orca-security-eu orca-security-eu bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Orca Security Scan Summary

Status Check Issues by priority
Passed Passed Infrastructure as Code high 0   medium 0   low 0   info 0 View in Orca
Passed Passed SAST high 0   medium 0   low 0   info 0 View in Orca
Passed Passed Secrets high 0   medium 0   low 0   info 0 View in Orca
Passed Passed Vulnerabilities high 0   medium 0   low 0   info 0 View in Orca

@tsmith023
Copy link
Collaborator

Looks like you need to call ruff format . on the codebase to appease the linter!

@tsmith023 tsmith023 merged commit 0851fe3 into weaviate:main Mar 24, 2026
123 checks passed
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