-
-
Notifications
You must be signed in to change notification settings - Fork 31.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use mypy-friendly conditional import for zoneinfo #50444
Conversation
|
||
import ciso8601 | ||
|
||
from homeassistant.const import MATCH_ALL | ||
|
||
if sys.version_info[:2] >= (3, 9): | ||
import zoneinfo # pylint: disable=import-error |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@cdce8p if you want to improve pylint a little bit more.
Mypy understands blocks inside sys.version_info
but pylint doesn't. But on the other side pylint doesn't complain about
try:
import x
except ImportError
import y
while mypy has this issue.
It'd be nice to support sys.version_info
in pylint as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You could use the ignored-modules
option, documentation or wait for pylint-dev/pylint#4468 😃
@balloob as you authored migration to |
Thanks for addressing this. I was already stuck with it hence I used the type ignore. |
Proposed change
After #50387 mypy fails locally for me with:
That's probably because I use Python 3.9 locally. My idea is that CI didn't catch it, because
zoneinfo
is marked as Python 3.9+ and the first import was just ignored.I think it's still nice to support Python 3.9 before CI is switched to it.
This is a known issue of mypy and using
sys.version_info
is suggested workaround: python/mypy#1153Type of change
Additional information
Checklist
black --fast homeassistant tests
)If user exposed functionality or configuration variables are added/changed:
If the code communicates with devices, web services, or third-party tools:
Updated and included derived files by running:
python3 -m script.hassfest
.requirements_all.txt
.Updated by running
python3 -m script.gen_requirements_all
..coveragerc
.The integration reached or maintains the following Integration Quality Scale:
To help with the load of incoming pull requests: