Skip to content

Remove star imports and enable F403/F405 Ruff checks#1207

Merged
bact merged 2 commits intodevfrom
copilot/remove-star-imports
Jan 16, 2026
Merged

Remove star imports and enable F403/F405 Ruff checks#1207
bact merged 2 commits intodevfrom
copilot/remove-star-imports

Conversation

Copy link
Contributor

Copilot AI commented Jan 15, 2026

What does this changes

Removes all star imports (from module import *) from the codebase and enables Ruff checks F403/F405 to prevent their reintroduction.

What was wrong

Star imports obscure the origin of imported names, making static analysis, type inference, and IDE autocomplete less effective. They were present in:

  • pythainlp/generate/thai2fit.py: from fastai.text import *
  • tests/extra/testx_ulmfit.py: from fastai.text import *
  • pythainlp/ulmfit/core.py: Docstring examples showing star imports

How this fixes it

Code changes:

  • Replace star imports with explicit imports of used names: AWD_LSTM, NumericalizeProcessor, TextList, TokenizeProcessor, Tokenizer, URLs, language_model_learner, untar_data
  • Update docstring examples to demonstrate explicit imports
  • Fix typo: document_vectorrdocument_vector

Configuration:

  • Remove F403/F405 from pyproject.toml ignored rules

Before:

from fastai.text import *

After:

from fastai.text import (
    AWD_LSTM,
    NumericalizeProcessor,
    TextList,
    TokenizeProcessor,
    Tokenizer,
    URLs,
    language_model_learner,
    untar_data,
)

Your checklist for this pull request

  • Passed code styles and structures
  • Passed code linting checks and unit test
Original prompt

This section details on the original issue you should resolve

<issue_title>Revise code to remove star imports</issue_title>
<issue_description>### Description

There are some module in the package that still use star imports (import *).
It is convenient for quick experiment but a bad practice for code that meant to be reused and maintained.
Star imports also make it difficult to infer type hints and there is less information for static code analysis.

Expected results

We should target to remove all those star imports in the code base and replace them with narrower/more specific imports.

This is a required step for PyThaiNLP to provide all the type hints and make the library more friendly to developers (IDEs, linters, and AI tools, etc. will work better).

Current results

There are some import *.

Steps to reproduce

Look at the code. Sometimes near the top, but sometimes the imports are in some other blocks.

PyThaiNLP version

5.2

Python version

Operating system and version

More info

No response

Possible solution

Try to find what are the actual functions that got import and used.
Then import only those functions.

Files

No response</issue_description>

<agent_instructions>Remove star imports, replace it with narrower imports, and improve type hinting.
Make sure they are done in safely manner.</agent_instructions>

Comments on the Issue (you are @copilot in this section)


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Co-authored-by: bact <128572+bact@users.noreply.github.com>
@sonarqubecloud
Copy link

@bact bact added the refactoring a technical improvement which does not add any new features or change existing features. label Jan 15, 2026
@bact bact added this to the 5.3 milestone Jan 15, 2026
Copilot AI changed the title [WIP] Revise code to remove star imports Remove star imports and enable F403/F405 Ruff checks Jan 15, 2026
Copilot AI requested a review from bact January 15, 2026 23:59
@bact bact added this to PyThaiNLP Jan 15, 2026
@bact bact marked this pull request as ready for review January 16, 2026 00:00
@coveralls
Copy link

coveralls commented Jan 16, 2026

Coverage Status

coverage: 53.507% (-0.05%) from 53.555%
when pulling ca80e67 on copilot/remove-star-imports
into 7842ad9 on dev.

@bact bact requested a review from wannaphong January 16, 2026 00:04
@bact bact merged commit 65a7788 into dev Jan 16, 2026
42 of 44 checks passed
@bact bact deleted the copilot/remove-star-imports branch January 30, 2026 13:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

refactoring a technical improvement which does not add any new features or change existing features.

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

Revise code to remove star imports

4 participants