Skip to content

fix: re-export symbols in __init__.py files#9521

Merged
anakin87 merged 3 commits intomainfrom
rexeport-symbols
Jun 16, 2025
Merged

fix: re-export symbols in __init__.py files#9521
anakin87 merged 3 commits intomainfrom
rexeport-symbols

Conversation

@anakin87
Copy link
Copy Markdown
Member

@anakin87 anakin87 commented Jun 16, 2025

Related Issues

Proposed Changes:

  • re-export symbols in __init__.py files to make shorter imports work without errors/warning from mypy/Pylance.
    • Shorter import example: from haystack.components.builders import ChatPromptBuilder instead of from haystack.components.builders.chat_prompt_builder import ChatPromptBuilder.
  • I implemented the solution suggested in the original issue and in Python typing docs

How did you test it?

  • CI
  • In a fresh virtual environment, I installed Haystack from the current branch. Pylance/mypy errors/warning related to short imports disappeared.

Checklist

  • I have read the contributors guidelines and the code of conduct
  • I have updated the related issue with new insights and changes
  • I added unit tests and updated the docstrings
  • I've used one of the conventional commit types for my PR title: fix:, feat:, build:, chore:, ci:, docs:, style:, refactor:, perf:, test: and added ! in case the PR includes breaking changes.
  • I documented my code
  • I ran pre-commit hooks and fixed any issue

@coveralls
Copy link
Copy Markdown
Collaborator

coveralls commented Jun 16, 2025

Pull Request Test Coverage Report for Build 15679340982

Details

  • 0 of 0 changed or added relevant lines in 0 files are covered.
  • 31 unchanged lines in 6 files lost coverage.
  • Overall coverage decreased (-0.2%) to 90.143%

Files with Coverage Reduction New Missed Lines %
components/embedders/init.py 1 42.86%
components/retrievers/init.py 1 54.55%
components/extractors/init.py 2 60.0%
components/rankers/init.py 2 46.15%
dataclasses/init.py 12 24.0%
utils/init.py 13 20.69%
Totals Coverage Status
Change from base Build 15679263320: -0.2%
Covered Lines: 11541
Relevant Lines: 12803

💛 - Coveralls

@anakin87 anakin87 changed the title chore: re-export symbols in __init__.py files fix: re-export symbols in __init__.py files Jun 16, 2025
@anakin87 anakin87 marked this pull request as ready for review June 16, 2025 11:21
@anakin87 anakin87 requested review from a team as code owners June 16, 2025 11:21
@anakin87 anakin87 requested review from dfokina and sjrl and removed request for a team June 16, 2025 11:21
Comment on lines +41 to +47
from .streaming_chunk import AsyncStreamingCallbackT as AsyncStreamingCallbackT
from .streaming_chunk import ComponentInfo as ComponentInfo
from .streaming_chunk import StreamingCallbackT as StreamingCallbackT
from .streaming_chunk import StreamingChunk as StreamingChunk
from .streaming_chunk import SyncStreamingCallbackT as SyncStreamingCallbackT
from .streaming_chunk import ToolCallDelta as ToolCallDelta
from .streaming_chunk import select_streaming_callback as select_streaming_callback
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

A little annoying this gets so much more verbose but I understand why

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I initially did something like
from .streaming_chunk import AsyncStreamingCallbackT as AsyncStreamingCallbackT, ComponentInfo as ComponentInfo, ...
but ruff automatically converted the code into this format

from .auth import Secret as Secret
from .auth import deserialize_secrets_inplace as deserialize_secrets_inplace
from .azure import default_azure_ad_token_provider as default_azure_ad_token_provider
from .base_serialization import _deserialize_value_with_schema as _deserialize_value_with_schema
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Do we need to do this for private methods as well?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I only applied the same change on everything present in __init__.py

I don't know why this specific method was originally exported in __init__.py
Maybe this is related:

# TODO: Make this function public once its implementation is finalized and tested
def _serialize_value_with_schema(payload: Dict[str, Any]) -> Dict[str, Any]:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

okay fair enough, let's leave it

Comment thread pyproject.toml
Comment on lines -240 to -242
"unnecessary-comprehension",
"subprocess-run-check",
"singleton-comparison",
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Just checking it seems like a lot of other unrelated disables were also removed?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

ah sorry, I forgot to mention this. This is an unrelated change I have done.
These ignored rules came from Haystack 1.x, so I removed from disabled rules all the rules that are not currently being violated.

@sjrl
Copy link
Copy Markdown
Contributor

sjrl commented Jun 16, 2025

@anakin87 looks good! Just a few comments.

Copy link
Copy Markdown
Contributor

@sjrl sjrl left a comment

Choose a reason for hiding this comment

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

Looks good!

@anakin87 anakin87 merged commit 7570f6b into main Jun 16, 2025
23 checks passed
@anakin87 anakin87 deleted the rexeport-symbols branch June 16, 2025 14:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

What is the correct way to import components? (aka pylance reportPrivateImportUsage error)

3 participants