Repository navigation
refactor(email): one definition of email_questions - #136
NandhaKishorM merged 2 commits into
Conversation
|
Thank you, two definitions of |
`email_questions` had two definitions, in `laya/email.py` and in `laya/presets.py`. The bodies were identical and the docstrings were not. `laya/__init__.py` re-exports the `presets` one. So `laya.email_questions` and `laya.email.email_questions` were two objects that happened to agree. They can stop agreeing, and nothing notices. Measured on 010bace, Python 3.14.7, macOS 25.6.0. Add a `legal` category to the copy in `laya/email.py`: laya.email_questions() -> no 'legal' laya.email.email_questions() -> 'legal' All 16 test files in the CI list exit 0, and ruff is clean. An edit to that copy is invisible to the documented API and to every check the project runs. The presets module holds the other four presets, and `__init__` already imports from it. So the definition stays there. `laya/email.py` re-exports it, because `from laya.email import email_questions` is a path callers already have. Rejected: * Delete the copy outright. The diff is smaller, but it removes a public import path from a library at 0.3.x that has no deprecation channel. * Move the definition into `laya/email.py` and import it in `presets`. That splits the five presets across two modules. `__init__` would then import four names from one module and one name from the other. `tests/test_email.py` gains the invariant: both module paths are one object. On 010bace it is 49 passed / 1 failed before and 50 passed / 0 failed after. First measured on 573e5b6: 14 / 1 before, 15 / 0 after. Three checks next to it pass in both states: the package export, equal output, and a caller override that reaches both paths. They hold the behaviour. The identity check holds the shape. With one definition, the same mutation reaches both paths. No import cycle. `laya/presets.py` imports only from `typing`. Checked in both orders and on the direct import. The 16 test files in the CI list, ruff and compileall all pass after the change.
095f9f7 to
fc8af4d
Compare
|
Rebased onto 010bace. Same conflict as #132: both sides append to
The drift is still there on 010bace, so I measured it again. I added a category to the copy in |
# Conflicts: # tests/test_email.py
|
Thank you for rebasing. After #227 landed both PRs appended to |
`email_questions` had two definitions, in `laya/email.py` and in `laya/presets.py`. The bodies were identical and the docstrings were not. `laya/__init__.py` re-exports the `presets` one. So `laya.email_questions` and `laya.email.email_questions` were two objects that happened to agree. They can stop agreeing, and nothing notices. Measured on 010bace, Python 3.14.7, macOS 25.6.0. Add a `legal` category to the copy in `laya/email.py`: laya.email_questions() -> no 'legal' laya.email.email_questions() -> 'legal' All 16 test files in the CI list exit 0, and ruff is clean. An edit to that copy is invisible to the documented API and to every check the project runs. The presets module holds the other four presets, and `__init__` already imports from it. So the definition stays there. `laya/email.py` re-exports it, because `from laya.email import email_questions` is a path callers already have. Rejected: * Delete the copy outright. The diff is smaller, but it removes a public import path from a library at 0.3.x that has no deprecation channel. * Move the definition into `laya/email.py` and import it in `presets`. That splits the five presets across two modules. `__init__` would then import four names from one module and one name from the other. `tests/test_email.py` gains the invariant: both module paths are one object. On 010bace it is 49 passed / 1 failed before and 50 passed / 0 failed after. First measured on 573e5b6: 14 / 1 before, 15 / 0 after. Three checks next to it pass in both states: the package export, equal output, and a caller override that reaches both paths. They hold the behaviour. The identity check holds the shape. With one definition, the same mutation reaches both paths. No import cycle. `laya/presets.py` imports only from `typing`. Checked in both orders and on the direct import. The 16 test files in the CI list, ruff and compileall all pass after the change. Co-authored-by: Nandakishor <48623612+NandhaKishorM@users.noreply.github.com>
Problem
email_questionsis defined twice, inlaya/email.py:70and inlaya/presets.py:45, withidentical bodies and different docstrings.
laya/__init__.py:17re-exports thepresetsone,so
laya.email_questionsandlaya.email.email_questionsare two objects that happen to agree.They can stop agreeing with nothing noticing. Adding a
legalcategory to the copy inlaya/email.py:and the checks do not react:
So an edit to that copy is invisible to the documented API and to everything the project runs.
Environment
Failing test
tests/test_email.pygains the invariant that both module paths are one object. Against theunchanged package:
Three checks sit next to it and pass in both states: the package export is that same object,
both paths answer the same, and a caller override reaches both paths. They hold the behaviour
while the identity check holds the shape.
Solution
+33 / -37 across two files.
laya/email.pydrops its copy and re-exports the one inlaya/presets.py:presets.pyowns the other four presets and is what__init__already imports from, so thedefinition stays there.
Rejected: deleting the copy outright. Smaller diff, but it removes a public import path from a
library at 0.3.5 with no deprecation channel, and the re-export costs one line.
Rejected the other way round, moving the definition into
laya/email.pyand importing it frompresets: that splits the five presets across two modules and leaves__init__importing fournames from one and one from the other.
No import cycle.
laya/presets.pyimports only fromtyping, and all three entry points work:Evidence
With one definition the same mutation reaches both paths:
The rest of the suite on
573e5b6, before and after, identical:ruff check laya/ --select=E9,F63,F7,F82,F401,F811 --line-length=120andpython -m compileall -q laya/ tests/clean.python -c "import laya; print(laya.__version__); print(sorted(laya.__all__))", the CI import step, lists the same 27 names and all resolve.Note
This branch is cut from
573e5b6and does not depend on #132 or #133. It touchestests/test_email.py, which #132 also extends, in a different place; whichever lands secondrebases.