Skip to content

Rename trio.hazmat → trio.lowlevel - #1484

Merged
oremanj merged 7 commits into
python-trio:masterfrom
njsmith:rename-hazmat-to-lowlevel
May 2, 2020
Merged

oremanj merged 7 commits into
python-trio:masterfrom
njsmith:rename-hazmat-to-lowlevel

Conversation

@njsmith

@njsmith njsmith commented May 1, 2020

Copy link
Copy Markdown
Member

Closes: gh-476

@njsmith
njsmith force-pushed the rename-hazmat-to-lowlevel branch from c79e795 to dc29752 Compare May 1, 2020 00:53
@codecov

codecov Bot commented May 1, 2020 •

Copy link
Copy Markdown

Codecov Report

Merging #1484 into master will increase coverage by 6.88%.
The diff coverage is 96.72%.

@@            Coverage Diff             @@
##           master    #1484      +/-   ##
==========================================
+ Coverage   92.78%   99.67%   +6.88%     
==========================================
  Files         106      107       +1     
  Lines       13216    13220       +4     
  Branches      995      995              
==========================================
+ Hits        12263    13177     +914     
+ Misses        900       28     -872     
+ Partials       53       15      -38     
Impacted Files Coverage Δ
trio/_abc.py 100.00% <ø> (ø)
trio/_core/__init__.py 100.00% <ø> (ø)
trio/_core/_entry_queue.py 100.00% <ø> (ø)
trio/_core/_exceptions.py 100.00% <ø> (ø)
trio/_core/_parking_lot.py 100.00% <ø> (ø)
trio/_core/_run.py 99.74% <ø> (+0.90%) ⬆️
trio/_core/_traps.py 100.00% <ø> (ø)
trio/_core/_unbounded_queue.py 100.00% <ø> (ø)
trio/hazmat.py 0.00% <0.00%> (-77.78%) ⬇️
trio/__init__.py 100.00% <100.00%> (ø)
... and 44 more

@pquentin pquentin left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks for tackling this! 🎉

While this works:

>>> import trio
>>> trio.hazmat
__main__:1: TrioDeprecationWarning: trio.hazmat is deprecated since Trio 0.15.0; use trio.lowlevel instead (https://github.com/python-trio/trio/issues/476)
<module 'trio.lowlevel' from '/Users/quentin/Software/trio/trio/lowlevel.py'>

This no longer works, is it expected?

>>> import trio.hazmat
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'trio.hazmat'

Comment thread newsfragments/476.removal.rst Outdated
@@ -0,0 +1,3 @@
It turns out that everyone got confused by the name ``trio.lowlevel``.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

s/lowlevel/hazmat/s

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.

Haha, whoops! nice catch :-)

Comment thread docs/source/reference-lowlevel.rst Outdated
You don't need to be scared of :mod:`trio.lowlevel`, as long as you
take proper precautions. These are real public APIs, with strictly
defined and carefully documented semantics. But, you should read
carefully and take proper precautions. Some of those strict semantics

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Is the phrase repetition with line 28 intentional? Perhaps something like this could also work:

But, you should pay attention while using them and certainly read the documentation in detail.

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.

Good point, tweaked the wording a bit.

@njsmith

njsmith commented May 1, 2020

Copy link
Copy Markdown
Member Author

@pquentin

This no longer works, is it expected?

>>> import trio.hazmat

Excellent question! I did not think about that.

I doubt many folks are writing import trio.hazmat, because import trio automatically gives you trio.hazmat. But I bet there are folks writing from trio.hazmat import ..., and it turns out that this change also broke that, for the same reason.

The issue is that when you refer to trio.hazmat.something, then it looks for the hazmat attribute on trio, and when the attribute isn't found, then it runs our __getattr__ fallback code, which issues the warning and then returns the proper value. BUT, import trio.hazmat tries to find trio/hazmat.py directly, without checking for an existing .hazmat attribute on trio.

I did find a workaround though: if we make a trio/hazmat.py file that issues a warning and then does from trio.lowlevel import *, then everything mostly works:

  • If you do trio.hazmat.blah then it works and gives a warning
  • If you do from trio.hazmat import blah then it works and gives a warning

The one issue is that after you do from trio.hazmat import ..., then any future accesses to trio.hazmat.whatever will stop issuing warnings (because the import machinery adds a real hazmat attribute to the trio module, so our __getattr__ fallback code never runs). But that's OK... it's technically not quite as nice because it defeats the part of the warnings module that tries to tell you about all the different places that are using the deprecated code, but we still preserve the key invariant that every program which uses trio.hazmat does print at least one warning.

@njsmith

njsmith commented May 1, 2020

Copy link
Copy Markdown
Member Author

Addressed review comments.

On further consideration, I think I want to make one more change: in the changelog, it's a bit awkward to handle all the old references to trio.hazmat, since on the one hand it's a historical document so you want to leave things alone, but on the other hand, it's something people read in the present.

The awkward compromise I did in the initial commit was to apply the search/replace to only the text that had live links. I think a better way would be to keep the text the same while fixing the link destinations only.

@njsmith

njsmith commented May 2, 2020

Copy link
Copy Markdown
Member Author

OK done, I think (hope?) this is ready now

@njsmith
njsmith requested a review from pquentin May 2, 2020 01:51
@oremanj
oremanj merged commit f07c4fb into python-trio:master May 2, 2020
@oremanj

oremanj commented May 2, 2020

Copy link
Copy Markdown
Member

Looks great, thank you!

@pquentin

pquentin commented May 2, 2020

Copy link
Copy Markdown
Member

Looks good to me too, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Should we rename trio.hazmat?

5 participants