-
Notifications
You must be signed in to change notification settings - Fork 122
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: remove as much 'if typing.TYPE_CHECKING:' as possible (#1034)
* Wherever possible, remove the 'if typing.TYPE_CHECKING:' guards. * Move the definition of the `_ConfigOption` `TypedDict` from `ops.testing` to `ops.model` - `model` should not import from `testing` (the import loop was avoided because it was only when `TYPE_CHECKING` but it's still poor practice) This leaves a few cases where we still use `TYPE_CHECKING`: * When using `typing_extensions`. We currently assume that if `TYPE_CHECKING` is true that the `requirements-dev` have been installed (or at least `typing_extensions` has). It seems like this would not always be the case (e.g. if type checking is being done on a charm that uses `ops`) but is the status-quo and avoids bringing `typing_extensions` into `requirements.txt`. Hopefully, we won't need it for anything after `Required`/`NotRequired` and once we have progressed our minimum Python version enough to get those, we can drop it entirely. * We override the definition of some class attributes to be properties when `TYPE_CHECKING` is true. Removing the guard would change the actual attributes. * In Python 3.8 we can't use `weakref.WeakValueDictionary[T]` with a type. We're currently assuming that a more recent version of Python will be used when type checking, but can't bring this out as that would raise the minimum Python version for all cases (or we'd need to adjust the typing so that it can work in 3.8).
- Loading branch information
1 parent
d7e15e8
commit e762ef8
Showing
9 changed files
with
196 additions
and
195 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.