Repository navigation
One import statement per module - #75
Conversation
Several `from <module> import ...` statements of one module in one scope (module level, `if TYPE_CHECKING:`, function body) are merged into one statement at the position of the first, continued by `\` and aligned to the first name's column. Each extra statement runs `IMPORT_NAME` once more (about 0.75 us on Python 3.15, 0.43 us on 3.13). pyTooling.Sphinx: 403 -> 358 import statements, tests: 171 -> 167. Imported names, the order in which modules are first imported and every module's namespace are unchanged (compared before/after). Co-Authored-By: Patrick Lehmann <Paebbels@gmail.com>
`pyTooling.Sphinx.DependencyTable` imported `DependencyError` (3x), `UnknownLicense` and `SPDXLicense` inside functions, while its module-level imports load `pyTooling.Dependency` and, through it, `pyTooling.Licensing` anyway. `_LicenseName` and `_LicenseURL` ran their import once per table row. The names join the module's import block; the first-import order of all modules is unchanged. Tests: `DEFAULT_VERSION_FORMAT`, `DEFAULT_DEPENDENCY_FORMAT` (module already imported by the test file) and `pygments.token` (loaded with Sphinx) move to the module level too. Kept function-local: imports of optional dependencies (pyEDAA.Reports, markdown-it-py, `requests`, `packaging`), lazily loaded modules (`pyTooling.Dependency.Python`/`.Resolver`, `xmlschema`), the cyclic imports of the report pages modules, and the submodule imports in `setup()`, `readReports()` and `checkReportConfiguration()`. pyTooling.Sphinx: 358 -> 354 import statements, tests: 167 -> 165. Co-Authored-By: Patrick Lehmann <Paebbels@gmail.com>
Up to standards ✅🟢 Issues
|
| Metric | Results |
|---|---|
| Complexity | 0 |
| Duplication | 0 |
🟢 Coverage 100.00% diff coverage · -0.04% coverage variation
Metric Results Coverage variation ✅ -0.04% coverage variation (-1.00%) Diff coverage ✅ 100.00% diff coverage Coverage variation details
Coverable lines Covered lines Coverage Common ancestor commit (ddeba52) 4899 4304 87.85% Head commit (bf1be1a) 4852 (-47) 4261 (-43) 87.82% (-0.04%) Coverage variation is the difference between the coverage for the head and common ancestor commits of the pull request branch:
<coverage of head commit> - <coverage of common ancestor commit>Diff coverage details
Coverable lines Covered lines Diff coverage Pull request (#75) 24 24 100.00% Diff coverage is the percentage of lines that are covered by tests out of the coverable lines that the pull request added or modified:
<covered lines added or modified>/<coverable lines added or modified> * 100%
NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## dev #75 +/- ##
==========================================
- Coverage 85.62% 85.57% -0.06%
==========================================
Files 24 24
Lines 4899 4852 -47
Branches 779 779
==========================================
- Hits 4195 4152 -43
+ Misses 595 591 -4
Partials 109 109
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Changes
from <module> import ...statement per module and scope: several statements of one module are merged into one, continued by\and aligned to the column of the first imported name - also insideif TYPE_CHECKING:blocks (tab, then spaces) and function bodies.pyTooling.Sphinx:HTML,LaTeX,Nodeat module level;Abbreviation,CodeCoverage,DocCoverage,ExternalLink,Roles,Unittestinsetup().pyTooling.Sphinx.CodeCoverage:pyTooling.Sphinx.pyTooling.Sphinx.CondensedClass:ast.pyTooling.Sphinx.CondensedSource:ast,typing.pyTooling.Sphinx.DependencyTable:typing,pyTooling.Sphinx,pyTooling.Dependency.Python(underif TYPE_CHECKING:).pyTooling.Sphinx.DocCoverage:typing,pyTooling.Sphinx.pyTooling.Sphinx.HTML,pyTooling.Sphinx.LaTeX,pyTooling.Sphinx.Tree:pyTooling.Sphinx.Node.pyTooling.Sphinx.Unittest:typing,pyTooling.Sphinx,pyEDAA.Reports.Unittesting(underif TYPE_CHECKING:).IMPORT_NAMEonce more: about 0.75 µs on Python 3.15 and 0.43 µs on 3.13 per statement. The package has 403 → 358 import statements.pyTooling.Sphinx.DependencyTable:DependencyError(3 functions),UnknownLicense(DependencyTable._LicenseName) andSPDXLicense(DependencyTable._LicenseURL) are imported at module level instead of inside the functions. The module's own imports loadpyTooling.Dependencyand, through it,pyTooling.Licensinganyway;_LicenseNameand_LicenseURLran their import once per table row. The first-import order of all modules is unchanged. The package then has 354 import statements.reports;CodeCoverage,CondensedSource,DocCoverage,Unittest), markdown-it-py and mdit-py-plugins (extramarkdown;GitHubMarkdown),requestsandpackaging.utils(behindMissingDependencyErrorfor thepypiextra;DependencyTable).pyTooling.Dependency.PythonandpyTooling.Dependency.Resolver(DependencyTable; also gated byif TYPE_CHECKING:at module level),xmlschema(XMLSchemaGraph).CodeCoveragePagesandUnittestPagesimportCodeCoverageandUnittest, which use them inside methods.setup(),readReports()andcheckReportConfiguration()inpyTooling.Sphinx: the submodules importpyTooling.Sphinx, andsetup()documents why it imports them.Unit Tests
tests/unit: 171 → 167 import statements (DependencyTable,Download,Extension,ExternalLink).DEFAULT_VERSION_FORMATandDEFAULT_DEPENDENCY_FORMAT(module already imported bytests/unit/DependencyTable.py) andpygments.token(loaded with Sphinx;tests/unit/CodeCoveragePages.py) are imported at module level instead of inside a testcase: 165 import statements. pyEDAA.Reports stays a local import intests/unit/DocCoverage.py.Related Issues and Pull-Requests