Skip to content

Commit

Permalink
Merge pull request #217 from nucleic/ruff-fixes
Browse files Browse the repository at this point in the history
Sort slots and __all__ attrs (fix linting issues)
  • Loading branch information
MatthieuDartiailh authored Dec 29, 2024
2 parents ae1370b + 646de37 commit 666108e
Show file tree
Hide file tree
Showing 13 changed files with 325 additions and 326 deletions.
70 changes: 35 additions & 35 deletions atom/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,58 +67,58 @@
__all__ = [
"Atom",
"AtomMeta",
"MissingMemberWarning",
"add_member",
"observe",
"set_default",
"clone_if_needed",
"Bool",
"Bytes",
"CAtom",
"Callable",
"ChangeDict",
"ChangeType",
"DefaultValue",
"GetAttr",
"GetState",
"Member",
"PostGetAttr",
"PostSetAttr",
"PostValidate",
"SetAttr",
"Validate",
"atomclist",
"atomdict",
"defaultatomdict",
"atomlist",
"atomref",
"atomset",
"Coerced",
"Constant",
"ContainerList",
"DefaultDict",
"DefaultValue",
"Delegator",
"Dict",
"DefaultDict",
"Enum",
"Event",
"FixedTuple",
"Float",
"FloatRange",
"ForwardInstance",
"ForwardSubclass",
"ForwardTyped",
"GetAttr",
"GetState",
"Instance",
"Int",
"List",
"Member",
"MissingMemberWarning",
"PostGetAttr",
"PostSetAttr",
"PostValidate",
"Property",
"cached_property",
"Bool",
"Bytes",
"Callable",
"Constant",
"Float",
"FloatRange",
"Int",
"Range",
"ReadOnly",
"Str",
"Value",
"Set",
"SetAttr",
"Signal",
"ForwardSubclass",
"Str",
"Subclass",
"Tuple",
"ForwardTyped",
"Typed",
"FixedTuple",
"ChangeDict",
"Validate",
"Value",
"add_member",
"atomclist",
"atomdict",
"atomlist",
"atomref",
"atomset",
"cached_property",
"clone_if_needed",
"defaultatomdict",
"observe",
"set_default",
]
2 changes: 1 addition & 1 deletion atom/instance.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ class ForwardInstance(Instance):
"""

__slots__ = ("resolve", "args", "kwargs", "optional")
__slots__ = ("args", "kwargs", "optional", "resolve")

def __init__(self, resolve, args=None, kwargs=None, *, factory=None, optional=None):
"""Initialize a ForwardInstance.
Expand Down
4 changes: 2 additions & 2 deletions atom/meta/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@

__all__ = [
"AtomMeta",
"observe",
"MissingMemberWarning",
"add_member",
"set_default",
"clone_if_needed",
"observe",
"set_default",
]
16 changes: 8 additions & 8 deletions atom/meta/atom_meta.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,22 +202,22 @@ class _AtomMetaHelper:
getstates: List[str]

__slots__ = (
"name",
"bases",
"dct",
"decorated",
"defaults",
"getstates",
"members",
"owned_members",
"specific_members",
"name",
"observes",
"defaults",
"validates",
"decorated",
"set_defaults",
"owned_members",
"post_getattrs",
"post_setattrs",
"post_validates",
"getstates",
"seen_decorated",
"set_defaults",
"specific_members",
"validates",
)

def __init__(self, name: str, bases: Tuple[type, ...], dct: Dict[str, Any]) -> None:
Expand Down
2 changes: 1 addition & 1 deletion atom/meta/member_modifiers.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
class set_default(object):
"""An object used to set the default value of a base class member."""

__slots__ = ("value", "name")
__slots__ = ("name", "value")

#: Name of the member for which a new default value should be set. Used by
#: the metaclass.
Expand Down
4 changes: 2 additions & 2 deletions atom/meta/observation.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def observe(*names: str, change_types: ChangeType = ChangeType.ANY) -> "ObserveH
class ObserveHandler(object):
"""An object used to temporarily store observe decorator state."""

__slots__ = ("pairs", "func", "funcname", "change_types")
__slots__ = ("change_types", "func", "funcname", "pairs")

#: List of 2-tuples which stores the pair information for the observers.
pairs: List[Tuple[str, Optional[str]]]
Expand Down Expand Up @@ -132,7 +132,7 @@ def clone(self) -> "ObserveHandler":
class ExtendedObserver(object):
"""A callable object used to implement extended observers."""

__slots__ = ("funcname", "attr")
__slots__ = ("attr", "funcname")

#: Name of the function on the owner object which should be used as the observer.
funcname: str
Expand Down
2 changes: 1 addition & 1 deletion atom/typed.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ class ForwardTyped(Typed):
"""

__slots__ = ("resolve", "args", "kwargs", "optional")
__slots__ = ("args", "kwargs", "optional", "resolve")

def __init__(self, resolve, args=None, kwargs=None, *, factory=None, optional=None):
"""Initialize a ForwardTyped.
Expand Down
1 change: 0 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
#
# The full license is in the file LICENSE, distributed with this software.
# --------------------------------------------------------------------------------------
import os

from setuptools import Extension, setup

Expand Down
2 changes: 1 addition & 1 deletion tests/test_get_set_state.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ def task():
@pytest.mark.parametrize("fn", ("c", "py"))
def test_bench_getstate_slots(benchmark, fn):
class Test(AtomBase):
__slots__ = ("foo", "bar")
__slots__ = ("bar", "foo")
name = Str("Name")
enabled = Bool(True)
rating = Float()
Expand Down
2 changes: 1 addition & 1 deletion tests/type_checking/test_annotations.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
member_type: atom.list.List[builtins.int]
member_value_type: builtins.list[builtins.int]
main: |
import io
import _io
from typing import Type
from atom.api import Atom, {{ member }}
Expand Down
64 changes: 32 additions & 32 deletions tests/type_checking/test_coerced.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,24 +16,24 @@
member_type: atom.coerced.Coerced[builtins.int, builtins.int]
member_value_type: builtins.int
- member: Coerced
member_instance: Coerced(io.StringIO, None, dict(initial_value=str(1)))
member_type: atom.coerced.Coerced[io.StringIO, io.StringIO]
member_value_type: io.StringIO
member_instance: Coerced(_io.StringIO, None, dict(initial_value=str(1)))
member_type: atom.coerced.Coerced[_io.StringIO, _io.StringIO]
member_value_type: _io.StringIO
- member: Coerced
member_instance: Coerced(io.StringIO, kwargs=dict(initial_value=str(1)))
member_type: atom.coerced.Coerced[io.StringIO, io.StringIO]
member_value_type: io.StringIO
member_instance: Coerced(_io.StringIO, kwargs=dict(initial_value=str(1)))
member_type: atom.coerced.Coerced[_io.StringIO, _io.StringIO]
member_value_type: _io.StringIO
- member: Coerced
member_instance: Coerced(io.StringIO, factory=g)
member_type: atom.coerced.Coerced[io.StringIO, io.StringIO]
member_value_type: io.StringIO
member_instance: Coerced(_io.StringIO, factory=g)
member_type: atom.coerced.Coerced[_io.StringIO, _io.StringIO]
member_value_type: _io.StringIO
main: |
import io
import _io
from typing import Type
from atom.api import Atom, {{ member }}
def g() -> io.StringIO:
return io.StringIO()
def g() -> _io.StringIO:
return _io.StringIO()
class A(Atom):
m = {{ member_instance }}
Expand All @@ -45,35 +45,35 @@
- case: coerced_coercer
parametrized:
- member: Coerced
member_instance: Coerced(io.StringIO, coercer=coercer)
member_type: atom.coerced.Coerced[io.StringIO, Union[io.StringIO, builtins.str]]
member_value_type: io.StringIO
member_instance: Coerced(_io.StringIO, coercer=coercer)
member_type: atom.coerced.Coerced[_io.StringIO, Union[_io.StringIO, builtins.str]]
member_value_type: _io.StringIO
- member: Coerced
member_instance: Coerced(io.StringIO, (), coercer=coercer)
member_type: atom.coerced.Coerced[io.StringIO, Union[io.StringIO, builtins.str]]
member_value_type: io.StringIO
member_instance: Coerced(_io.StringIO, (), coercer=coercer)
member_type: atom.coerced.Coerced[_io.StringIO, Union[_io.StringIO, builtins.str]]
member_value_type: _io.StringIO
- member: Coerced
member_instance: Coerced(io.StringIO, None, dict(initial_value=str(1)), coercer=coercer)
member_type: atom.coerced.Coerced[io.StringIO, Union[io.StringIO, builtins.str]]
member_value_type: io.StringIO
member_instance: Coerced(_io.StringIO, None, dict(initial_value=str(1)), coercer=coercer)
member_type: atom.coerced.Coerced[_io.StringIO, Union[_io.StringIO, builtins.str]]
member_value_type: _io.StringIO
- member: Coerced
member_instance: Coerced(io.StringIO, kwargs=dict(initial_value=str(1)), coercer=coercer)
member_type: atom.coerced.Coerced[io.StringIO, Union[io.StringIO, builtins.str]]
member_value_type: io.StringIO
member_instance: Coerced(_io.StringIO, kwargs=dict(initial_value=str(1)), coercer=coercer)
member_type: atom.coerced.Coerced[_io.StringIO, Union[_io.StringIO, builtins.str]]
member_value_type: _io.StringIO
- member: Coerced
member_instance: Coerced(io.StringIO, factory=g, coercer=coercer)
member_type: atom.coerced.Coerced[io.StringIO, Union[io.StringIO, builtins.str]]
member_value_type: io.StringIO
member_instance: Coerced(_io.StringIO, factory=g, coercer=coercer)
member_type: atom.coerced.Coerced[_io.StringIO, Union[_io.StringIO, builtins.str]]
member_value_type: _io.StringIO
main: |
import io
import _io
from typing import Type
from atom.api import Atom, {{ member }}
def coercer(x: str) -> io.StringIO:
return io.StringIO(x)
def coercer(x: str) -> _io.StringIO:
return _io.StringIO(x)
def g() -> io.StringIO:
return io.StringIO()
def g() -> _io.StringIO:
return _io.StringIO()
class A(Atom):
m = {{ member_instance }}
Expand Down
2 changes: 1 addition & 1 deletion tests/type_checking/test_subclass.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
member_type: atom.subclass.ForwardSubclass[Union[type[builtins.int], type[main.A], type[builtins.str]]]
member_value_type: Union[type[builtins.int], type[main.A], type[builtins.str]]
main: |
import io
import _io
from typing import Tuple, Type
from atom.api import Atom, {{ member }}
Expand Down
Loading

0 comments on commit 666108e

Please sign in to comment.