-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow aliased or extended builtin imports in device modules
- Closes #56
- Loading branch information
1 parent
7122c0b
commit 8e3c7bb
Showing
3 changed files
with
58 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
from typing import TypedDict | ||
|
||
from ophyd.utils import DisconnectedError | ||
from math import hypot, log | ||
|
||
|
||
""" | ||
Some builtins (e.g. dict, Exception), types that extend | ||
them, and aliases for them, do not have signature information. | ||
PEP-8 recommends being conservative with adding typing information | ||
to builtins and the core Python library, so this may change slowly. | ||
This beamline uses some types or constructions that are known to | ||
cause issue but that could conceivably be used in a beamline file. | ||
- Importing specific exceptions | ||
- Importing functions from builtins, including math | ||
- Aliasing builtins, including dict | ||
- Defining a class that extends TypedDict (e.g. for parameters) | ||
""" | ||
|
||
|
||
def not_a_device() -> None: | ||
""" | ||
Importing DisconnectedError is enough to cause issue, but we | ||
use it here to prevent linting from removing it from the imports. | ||
""" | ||
raise DisconnectedError() | ||
|
||
|
||
def also_not_a_device() -> float: | ||
""" | ||
log and hypot both do not have signatures. | ||
Not required to actually be used, importing is enough. | ||
""" | ||
return log(hypot(0, 0)) | ||
|
||
|
||
a = dict | ||
b = Exception | ||
|
||
|
||
class B(TypedDict): | ||
""" | ||
Causes issue only if a class that extends TypedDict exists. | ||
""" | ||
foo: int |
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