Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 45
Static Type Checking: Enums#2153
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
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -35,6 +35,9 @@ class FastEnum(metaclass=MetaFastEnum): | ||||||
| :class:`enum.Enum` attributes accesses can be really slow, and slow down the execution noticeably. | ||||||
| This reimplementation doesn't suffer the same problems, but also does not reimplement everything. | ||||||
| For mypy Enum static type checking support, all FastEnum should be stubbed as inheriting from enum.Enum. | ||||||
| Use `stubgen src/buildstream/types.py --include-docstrings` to generate the stubs, add `from enum import Enum` and replace all `(FastEnum)` with `(Enum)` | ||||||
| """ | ||||||
| name = None | ||||||
| @@ -61,7 +64,7 @@ def __new__(cls, value): | ||||||
| try: | ||||||
| return cls._value_to_entry[value] | ||||||
| except KeyError: | ||||||
| if type(value) is cls: # pylint: disable=unidiomatic-typecheck | ||||||
| if isinstance(value, cls): # pylint: disable=unidiomatic-typecheck | ||||||
Contributor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. AFAICT your are now doing this right. https://pylint.pycqa.org/en/latest/user_guide/messages/convention/unidiomatic-typecheck.html
Suggested change
So you dont need to disable the lint. | ||||||
| return value | ||||||
| raise ValueError("Unknown enum value: {}".format(value)) | ||||||
| @@ -169,7 +172,6 @@ class OverlapAction(FastEnum): | ||||||
| # Defines the scope of dependencies to include for a given element | ||||||
| # when iterating over the dependency graph in APIs like | ||||||
| # Element._dependencies(). | ||||||
| # | ||||||
| class _Scope(FastEnum): | ||||||
| # All elements which the given element depends on, following | ||||||
| @@ -384,7 +386,7 @@ def new_from_node(cls, node: MappingNode) -> "_SourceMirror": | ||||||
| alias_node: MappingNode = node.get_mapping("aliases") | ||||||
| for alias, uris in alias_node.items(): | ||||||
| assert type(uris) is SequenceNode # pylint: disable=unidiomatic-typecheck | ||||||
| assert isinstance(uris, SequenceNode) # pylint: disable=unidiomatic-typecheck | ||||||
| aliases[alias] = uris.as_str_list() | ||||||
| return cls(name, aliases) | ||||||
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.