Skip to content

fix(spacy): preserve positional language argument - #59

Merged
yisding merged 3 commits into
mainfrom
codex/fix-pysbdfactory-positional-argument-issue
Jun 12, 2026
Merged

yisding merged 3 commits into
mainfrom
codex/fix-pysbdfactory-positional-argument-issue

Conversation

@yisding

@yisding yisding commented Jun 12, 2026

Copy link
Copy Markdown
Owner

Motivation

  • A recent change to the spaCy component constructor made the second positional argument be treated as the component name (defaulting language to "en") which broke callers using the legacy positional SentenceSplitFactory(nlp, "fr") pattern and caused silent mis-segmentation for non-English text.
  • The intent is to restore backward compatibility so that a supported ISO language code passed positionally continues to select the language while keeping explicit spaCy factory name usage intact.

Description

  • Add LANGUAGE_CODES import and _DEFAULT_COMPONENT_NAME constant and update SentenceSplitFactory.__init__ to detect when the provided name matches a supported language code and swap name/language accordingly (if language == "en" and name != _DEFAULT_COMPONENT_NAME and name in LANGUAGE_CODES: language = name; name = _DEFAULT_COMPONENT_NAME).
  • Keep existing behavior for explicit spaCy factory construction via create_sentencesplit(nlp, name, language) so custom component names and explicit language= keywords remain unchanged.
  • Add regression tests in tests/test_spacy_component.py verifying positional SentenceSplitFactory(None, "fr") selects French and that create_sentencesplit(None, "custom_sentences", "fr") preserves both name and language.
  • Apply formatting fixes to satisfy ruff and ensure import ordering.

Testing

  • Ran uv run pytest tests/test_spacy_component.py --color yes and the new spacy-component tests passed (no failures).
  • Ran uv run ruff check . and uv run ruff format --check . which passed after fixing import ordering and formatting issues.
  • Ran uv run pytest tests/test_spacy_component.py tests/lang/test_french.py --color yes and the targeted tests completed successfully (19 passed, 1 warning).

Codex Task

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 8ae5394bba

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread sentencesplit/spacy_component.py Outdated
@yisding
yisding merged commit 3b577f3 into main Jun 12, 2026
7 checks passed
@yisding
yisding deleted the codex/fix-pysbdfactory-positional-argument-issue branch June 12, 2026 06:57
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.

1 participant