Commit Graph

61 Commits (3188a364e270c2753ba978dc2f1929e1d2148142)

Author SHA1 Message Date
Franck Nijhof c8b0a3b667
Revert "Move Platform StrEnum to const" (#60875) 2021-12-02 14:19:08 -08:00
Franck Nijhof 6e220d5d17
Move Platform StrEnum to const (#60857) 2021-12-02 22:30:52 +01:00
J. Nick Koston 1cd9be7538
Fix recursive limit in find_next_time_expression_time (#58914)
* Fix recursive limit in find_next_time_expression_time

* Add test case

* Update test_event.py

Co-authored-by: Erik Montnemery <erik@montnemery.com>
2021-11-02 00:11:17 +01:00
Otto Winter a9c0f89c09
Fix find_next_time_expression_time (#58894)
* Better tests

* Fix find_next_time_expression_time

* Add tests for Nov 7th 2021, Chicago transtion

* Update event tests

* Update test_event.py

* small performance improvement

Co-authored-by: J. Nick Koston <nick@koston.org>
Co-authored-by: Erik Montnemery <erik@montnemery.com>
2021-11-01 17:45:13 +01:00
Marc Mueller 7af67d34cf
Use assignment expressions 01 (#56394) 2021-09-18 13:31:35 -10:00
Daniel Hjelseth Høyer fbad453c89
Pylint 2.9.3 (#52972)
Co-authored-by: Marc Mueller <30130371+cdce8p@users.noreply.github.com>
2021-07-14 21:44:57 -07:00
Erik Montnemery 15e2c6d7dc
Fix typing for dt_util as_timestamp (#50886)
* Fix typing for dt_util::as_timestamp

* Apply suggestions from code review
2021-05-22 09:34:49 +02:00
Ruslan Sayfutdinov de5472403b
Use mypy-friendly conditional import for zoneinfo (#50444) 2021-05-13 22:36:49 -07:00
Paul Ganssle efa5c59559
Replace hand-rolled binary search with bisect_left (#50410)
The `bisect` module exposes a `bisect_left` function which does
basically what the bulk of `_lower_bound` does. From my tests, it is
slightly faster (~5%) in the probably common ideal case where `arr` is short.
In the worst case scenario, `bisect.bisect_left` is *much* faster.

```
>>> arr = list(range(60))
>>> cmp = 59
>>> %timeit _lower_bound(arr, cmp)
736 ns ± 6.24 ns per loop (mean ± std. dev. of 7 runs, 1000000 loops each)
>>> %timeit bisect_lower_bound(arr, cmp)
290 ns ± 7.77 ns per loop (mean ± std. dev. of 7 runs, 1000000 loops each)
```

I doubt this is a huge bottleneck or anything, but I think it's a bit
more readable, and it's more efficient, so it seems like it's mostly a
win.

This commit *will* add a new unconditional import for `bisect` when
importing `util.dt`, and `bisect` is not currently imported for any of
the standard library modules. It is possible to make this conditional by
placing `import bisect` in the _lower_bound function, or in the function
it's nested in.
2021-05-11 08:18:20 -07:00
Paulus Schoutsen f8584c3ded
Use zoneinfo instead of dateutil (#50387)
Co-authored-by: J. Nick Koston <nick@koston.org>
2021-05-10 08:32:29 -07:00
J. Nick Koston bf2d40adfe
Migrate from pytz to python-dateutil (#49643)
Co-authored-by: Paulus Schoutsen <balloob@gmail.com>
2021-05-07 22:46:26 -07:00
Franck Nijhof 6932cf9534
Use contextlib.suppress where possible (#48189) 2021-03-23 14:36:43 +01:00
Franck Nijhof 8a56dbf587
Add flake8 comprehensions checks to pre-commit & CI (#48111) 2021-03-19 13:41:09 +01:00
Marc Mueller fabd73f08b
Update typing 03 (#48015) 2021-03-17 21:46:07 +01:00
Paulus Schoutsen edf70e9f06
Make input_datetime better handle timezones (#43396)
* Make input_datetime better handle timezones

* Improve test coverage

* Apply suggestions from code review

Co-authored-by: Martin Hjelmare <marhje52@gmail.com>

* Revert change to time format

Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
2020-11-26 20:20:10 +01:00
J. Nick Koston a9de9c62f1
Use native utc timezone for utcnow() (#41727)
This allows timezone operations to happen in C code instead
of the pure-python code of pytz
2020-10-12 17:43:21 -05:00
Dmitry b106149588
Fix string parameter processing in parse_time_expression (#41468) (#41469) 2020-10-09 11:48:49 +02:00
J. Nick Koston 42227c1c53
Improve the performance of dt_util.utcnow() (#39145) 2020-08-23 09:57:58 +02:00
Jelle Raaijmakers ef254a1c3d
Round time values in get_age() to better approximate the actual age (#37125) 2020-07-09 11:19:38 -07:00
Ville Skyttä b4404b071f
Pylint cleanups (#35409)
* Avoid some outer name redefinitions

* Remove unneeded directives

* Narrow directive scope

* Don't disable redefined-variable-type
2020-05-09 14:08:40 +03:00
Franck Nijhof 71a47fc80c
Enable pylint global-statement (#33641) 2020-04-04 20:10:55 +02:00
Ruslan Sayfutdinov 15b4975681
Use ciso8601 library to parse datetime faster (#32128) 2020-02-24 08:33:10 -08:00
Ville Skyttä fa4fa30461 Various string cleanups (#30435)
* Remove some unnecessary string concatenations

* Replace some simple str.formats with f-strings

* Replace some string concatenations with f-strings
2020-01-03 14:47:06 +01:00
Ville Skyttä e6388e186c
Remove unnecessary string literal concatenations (#30360) 2020-01-02 21:17:10 +02:00
Bas Nijholt 67c56c860d Sort imports according to PEP8 for 'homeassistant' folder (#29789)
Components are already done
2019-12-09 16:42:10 +01:00
Ville Skyttä 761d7f21e9 Upgrade pylint (#27279)
* Upgrade pylint to 2.4.2 and astroid to 2.3.1

https://pylint.readthedocs.io/en/latest/whatsnew/2.4.html
https://pylint.readthedocs.io/en/latest/whatsnew/changelog.html#what-s-new-in-pylint-2-4-1
https://pylint.readthedocs.io/en/latest/whatsnew/changelog.html#what-s-new-in-pylint-2-4-2

* unnecessary-comprehension fixes

* invalid-name fixes

* self-assigning-variable fixes

* Re-enable not-an-iterable

* used-before-assignment fix

* invalid-overridden-method fixes

* undefined-variable __class__ workarounds

https://github.com/PyCQA/pylint/issues/3090

* no-member false positive disabling

* Remove some no longer needed disables

* using-constant-test fix

* Disable import-outside-toplevel for now

* Disable some apparent no-value-for-parameter false positives

* invalid-overridden-method false positive disables

https://github.com/PyCQA/pylint/issues/3150

* Fix unintentional Entity.force_update override in AfterShipSensor
2019-10-07 08:17:39 -07:00
Franck Nijhof 2f0eb07624 Migrate legacy typehints in core to PEP-526 (#26403)
* Migrate legacy typehints in core to PEP-526

* Fix one type
2019-09-03 20:36:04 -07:00
Franck Nijhof decf13b948 Use literal string interpolation in core (f-strings) (#26166) 2019-08-23 09:53:33 -07:00
Paulus Schoutsen 620cb74050 Type 2019-07-31 13:08:31 -07:00
Paulus Schoutsen 4de97abc3a Black 2019-07-31 12:25:30 -07:00
Anders Melchiorsen a439e087e1 Fix time expression parsing (#24696) 2019-06-22 13:39:33 +02:00
Otto Winter 26cf5acd5b Make async_track_time_change smarter (#17199)
* Make async_track_time_change smarter

* Move to util/dt

* Remove unnecessary check

* Lint

* Remove tzinfo check

* Remove check

* Add comment about async_track_point_in_utc_time

* Fix typing check

* Lint
2018-10-09 10:14:18 +02:00
Ville Skyttä ee696643cd Isort preparations (#16555)
* Don't treat typing as an "in-between" module for import order

That was a < 3.5 era thing.

* Tighten scope of some pylint unused-import disables

To avoid isort moving a top level one around, undesirably broadening its
scope.
2018-09-11 11:21:48 +02:00
Ville Skyttä 3800f00564 Disable assuming Optional type for values with None default (#16029)
https://www.python.org/dev/peps/pep-0484/#union-types
"Type checkers should move towards requiring the optional type to be
made explicit."
2018-08-17 20:22:49 +02:00
Ville Skyttä eee9b50b70 Upgrade pylint to 2.0.1 (#15683)
* Upgrade pylint to 2.0.1

* Pylint 2 bad-whitespace fix

* Pylint 2 possibly-unused-variable fixes

* Pylint 2 try-except-raise fixes

* Disable pylint fixme for todoist for now

https://github.com/PyCQA/pylint/pull/2320

* Disable pylint 2 useless-return for now

https://github.com/PyCQA/pylint/issues/2300

* Disable pylint 2 invalid-name for type variables for now

https://github.com/PyCQA/pylint/issues/1290

* Disable pylint 2 not-an-iterable for now

https://github.com/PyCQA/pylint/issues/2311

* Pylint 2 unsubscriptable-object workarounds

* Disable intentional pylint 2 assignment-from-nones

* Disable pylint 2 unsupported-membership-test apparent false positives

* Disable pylint 2 assignment-from-no-return apparent false positives

* Disable pylint 2 comparison-with-callable false positives

https://github.com/PyCQA/pylint/issues/2306
2018-07-26 08:55:42 +02:00
Andrey 140a874917 Add typing to homeassistant/*.py and homeassistant/util/ (#15569)
* Add typing to homeassistant/*.py and homeassistant/util/

* Fix wrong merge

* Restore iterable in OrderedSet

* Fix tests
2018-07-23 10:24:39 +02:00
Ville Skyttä b7c336a687 Pylint cleanups (#15626)
* Pylint 2 no-else-return fixes

* Remove unneeded abstract-class-not-used pylint disable
2018-07-23 10:16:05 +02:00
Andrey c2fe0d0120
Make typing checks more strict (#14429)
## Description:

Make typing checks more strict: add `--strict-optional` flag that forbids implicit None return type. This flag will become default in the next version of mypy (0.600)

Add `homeassistant/util/` to checked dirs.

## Checklist:
  - [x] The code change is tested and works locally.
  - [x] Local tests pass with `tox`. **Your PR cannot be merged unless tests pass**
2018-07-13 13:24:51 +03:00
Ville Skyttä b92350fb55 Lint cleanup (#15103)
* Remove unneeded inline pylint disables

* Remove unneeded noqa's

* Use symbol names instead of message ids in inline pylint disables
2018-06-25 13:05:07 -04:00
Ville Skyttä 4bd7a7eee3 Remove inline pylint disables for messages disabled in pylintrc (#14978) 2018-06-16 00:15:46 +02:00
Otto Winter 678f284015 Upgrade pylint to 1.8.2 (#12274)
* Upgrade pylint to 1.8.1

* Fix no-else-return

* Fix bad-whitespace

* Fix too-many-nested-blocks

* Fix raising-format-tuple

See https://github.com/PyCQA/pylint/blob/master/doc/whatsnew/1.8.rst

* Fix len-as-condition

* Fix logging-not-lazy

Not sure about that TEMP_CELSIUS though, but internally it's probably just like if you concatenated any other (variable) string

* Fix stop-iteration-return

* Fix useless-super-delegation

* Fix trailing-comma-tuple

Both of these seem to simply be bugs:
 * Nest: The value of self._humidity never seems to be used anywhere
 * Dovado: The called API method seems to expect a "normal" number

* Fix redefined-argument-from-local

* Fix consider-using-enumerate

* Fix wrong-import-order

* Fix arguments-differ

* Fix missed no-else-return

* Fix no-member and related

* Fix signatures-differ

* Revert "Upgrade pylint to 1.8.1"

This reverts commit af78aa00f125a7d34add97b9d50c14db48412211.

* Fix arguments-differ

* except for device_tracker

* Cleanup

* Fix test using positional argument

* Fix line too long

I forgot to run flake8 - shame on me... 🙃

* Fix bad-option-value for 1.6.5

* Fix arguments-differ for device_tracker

* Upgrade pylint to 1.8.2

* 👕 Fix missed no-member
2018-02-11 09:20:28 -08:00
Ville Skyttä 384f63dd1d Typing fixes (#12015)
* .gitignore: Add .mypy_cache

* Typing fixes
2018-01-29 00:24:08 -08:00
Fabian Affolter 8ba41563c9 Disable invalid-sequence-index (#7177) 2017-04-19 14:09:00 +02:00
Fabian Affolter be272ac64a Disable too-many-* (#4107)
* Disable too-many-* and too-few-public-methods

* Remove globally disabled pylint warnings
2016-10-30 22:18:53 +01:00
Pascal Vizeli d5368f6f78 Async bootstrap / component init (#3991)
* Async bootstrap

* Adress comments

* Fix tests

* More fixes

* Tests fixes
2016-10-27 00:16:23 -07:00
Fabian Heredia Montiel 0377338a81 Improvement typing (#2735)
* Fix: Circular dependencies of internal files

* Change: dt.date for Date and dt.datetime for DateTime

* Use NewType if available

* FIX: Wrong version test

* Remove: Date and DateTime types due to error

* Change to HomeAssistantType

* General Improvement of Typing

* Improve typing config_validation

* Improve typing script

* General Typing Improvements

* Improve NewType check

* Improve typing db_migrator

* Improve util/__init__ typing

* Improve helpers/location typing

* Regroup imports and remove pylint: disable=ungrouped-imports

* General typing improvements
2016-08-07 16:26:35 -07:00
Fabian Heredia Montiel d4f78e8552 Type Hints - Core/Utils/Helpers Part 1 (#2592)
* Fix deprecated(moved) import

* Add util/dt typing

* Green on mypy util/dt

* Fix some errors

* First part of yping util/yaml

* Add more typing to util/yaml
2016-07-23 11:07:08 -07:00
Johann Kellerman a60a342864 Logbook: Query databse as_utc(). dt: Use pytz's localize (#2521) 2016-07-13 18:45:55 -07:00
Daniel Høyer Iversen 630b7377bd Refactor get_age in util/dt (#2067) 2016-05-14 12:05:46 -07:00
Robbie Trencheny 16933abce9 Remove humanize and use a relative time thing that @balloob found on Github 2016-05-10 00:04:53 -07:00