Skip to content

feat: ship py.typed and pass mypy --strict - #3

Merged
alexandrecuer merged 6 commits into
Open-Building-Management:mainfrom
davidski:feat/strict-typing
Nov 16, 2026
Merged

alexandrecuer merged 6 commits into
Open-Building-Management:mainfrom
davidski:feat/strict-typing

Conversation

@davidski

@davidski davidski commented Nov 14, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Makes the package PEP 561 typed so downstream users like Home Assistant can type-check against it. HA's strict-typing rule requires integration libraries to ship py.typed. My intent is to move the emoncms integration up the quality scale a notch or two.

 pyemoncms/
+├── py.typed                # PEP 561 marker, added to package_data in setup.py
 └── emoncms_client.py
+      from __future__ import annotations   # `str | None` hints load on Python 3.9
-      url: str = None
+      url: str = ""
-      api_key: str = None
+      api_key: str | None = None
-      timeout=self.request_timeout
+      timeout=ClientTimeout(total=self.request_timeout)
-      async_get_feed_fields(...) -> list[str, Any] | None
+      async_get_feed_fields(...) -> list[Any] | None
+      cast(...) on JSON returns, `self: Self` on __aenter__

Evidence

  • Before (main):
    mypy --strict pyemoncms   -> Found 9 errors in 1 file
    python3.9 -c "import pyemoncms"
      -> TypeError: unsupported operand type(s) for |: 'type' and 'NoneType'
    
    After:
    mypy --strict pyemoncms   -> Success: no issues found in 2 source files
    python3.9 -c "import pyemoncms"  -> ok
    
  • Existing tests: 8/8 pass, pylint 10/10.

Merge Danger

Door: two-way

Blast Radius: small

  • url now defaults to "" instead of None. Every caller passes a URL, so in practice nothing changes.
  • python_requires=">=3.9" is now correct: on main the package fails to import on 3.9. 😬

@davidski
davidski force-pushed the feat/strict-typing branch 2 times, most recently from 6dd7d32 to 9603c12 Compare November 16, 2026 14:57
@alexandrecuer
alexandrecuer marked this pull request as ready for review November 16, 2026 15:02
@alexandrecuer

Copy link
Copy Markdown
Contributor

@davidski : nice improvment, thanks

@alexandrecuer

Copy link
Copy Markdown
Contributor

so I shall make the v0.1.4 on this basis so you can bump in homeassistant (just a bump commit so they can accept quickly). Right for yu ?

@davidski

Copy link
Copy Markdown
Contributor Author

Thanks so much! Hold on for just a moment. I'm tracking down a possible glitch with the type conversions.

@alexandrecuer
alexandrecuer merged commit a1f8885 into Open-Building-Management:main Nov 16, 2026
4 checks passed
@alexandrecuer

alexandrecuer commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

I've merged but no problem for another PR
there is no rush for the package

@davidski

Copy link
Copy Markdown
Contributor Author

@alexandrecuer Thanks for merging! An apology and a heads-up:

When I rebased this branch after #2 merged, I force-pushed over your commit that pulled in main, without noticing it was yours. Your follow-up merge then brought back a commit I'd meant to drop from this PR: it removes logging.basicConfig() from emoncms_client.py and moves that call into the README example. So main now ships that change, and it isn't mentioned in the PR description.

The effect: the library no longer configures the root logger on import. Applications that set up logging themselves (Home Assistant does) see no difference. Scripts that never call logging.basicConfig() will stop printing pyemoncms's error messages.

Happy to go either way: keep it (it's the usual practice for libraries), or I'll send a PR restoring the old behavior. Just let me know.

Separately, #4 fixes two typing gaps from this PR: a wrong return type on async_get_feed_fields and missing re-exports.

Sorry for the confusion, and I'll check before force-pushing shared branches in future.

@alexjunk

Copy link
Copy Markdown

Happy to go either way: keep it (it's the usual practice for libraries), or I'll send a PR restoring the old behavior. Just let me know.

Let's keep it like you did. It is a better design :-)

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.

3 participants