Skip to content

Commit

Permalink
Use ruff for linting and formatting (#205)
Browse files Browse the repository at this point in the history
* use ruff for linting and formatting

* cis: update cis workflow

* fix examples

* tests: disable memory tests on CI on MacOS

* tests: update typing tests

* tests: add missing skip reason

* tests: add some extra tests

* fix tests

* tests: improve tests
  • Loading branch information
MatthieuDartiailh authored Nov 22, 2023
1 parent 5a6a70d commit a816bb3
Show file tree
Hide file tree
Showing 26 changed files with 517 additions and 126 deletions.
13 changes: 5 additions & 8 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,18 +40,15 @@ jobs:
- name: Install dependencies
run: |
pip install -U -r lint_requirements.txt
- name: Isort
run: |
isort atom examples tests -c
- name: Black
- name: Formatting
if: always()
run: |
black atom examples tests --check
- name: Flake8
ruff format atom examples tests --check
- name: Linting
if: always()
run: |
flake8 atom examples tests
- name: Run Mypy
ruff atom examples tests
- name: Typing
if: always()
run: |
mypy atom examples
Expand Down
23 changes: 10 additions & 13 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,18 +1,15 @@
repos:
- repo: https://github.com/pre-commit/mirrors-isort
rev: v5.10.1
hooks:
- id: isort
- repo: https://github.com/psf/black
rev: 23.1.0
hooks:
- id: black
- repo: https://github.com/PyCQA/flake8
rev: 6.0.0
hooks:
- id: flake8
repos:
- repo: https://github.com/astral-sh/ruff-pre-commit
# Ruff version.
rev: v0.1.5
hooks:
# Run the linter.
- id: ruff
# Run the formatter.
- id: ruff-format
- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.0.0
rev: v1.7.0
hooks:
- id: mypy
additional_dependencies: []
3 changes: 3 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ Welcome to Atom
.. image:: https://readthedocs.org/projects/atom/badge/?version=latest
:target: https://atom.readthedocs.io/en/latest/?badge=latest
:alt: Documentation Status
.. image:: https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json
:target: https://github.com/astral-sh/ruff
:alt: Ruff

Atom is a framework for creating memory efficient Python objects with enhanced
features such as dynamic initialization, validation, and change notification for
Expand Down
2 changes: 1 addition & 1 deletion atom/atom.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ def __reduce_ex__(self, proto):
fully understands the rammifications.
"""
args = (type(self),) + self.__getnewargs__()
args = (type(self), *self.__getnewargs__())
return (__newobj__, args, self.__getstate__())

def __getnewargs__(self):
Expand Down
18 changes: 9 additions & 9 deletions atom/catom.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,15 @@ from .atom import Atom
from .property import Property
from .typing_utils import ChangeDict

class ChangeType(IntFlag):
CREATE = ...
UPDATE = ...
DELETE = ...
EVENT = ...
PROPERTY = ...
CONTAINER = ...
ANY = ...

def reset_property(prop: Property[Any, Any], owner: Atom) -> None: ...

class CAtom:
Expand Down Expand Up @@ -556,12 +565,3 @@ class GetState(IntEnum):
Property = ...
MemberMethod_Object = ...
ObjectMethod_Name = ...

class ChangeType(IntFlag):
CREATE = ...
UPDATE = ...
DELETE = ...
EVENT = ...
PROPERTY = ...
CONTAINER = ...
ANY = ...
9 changes: 7 additions & 2 deletions atom/coerced.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,14 @@ def __init__(self, kind, args=None, kwargs=None, *, factory=None, coercer=None):
args = args or ()
kwargs = kwargs or {}
if opt:
factory = lambda: None

def factory():
return None
else:
factory = lambda: kind[0](*args, **kwargs)

def factory():
return kind[0](*args, **kwargs)

self.set_default_value_mode(DefaultValue.CallObject, factory)

if not coercer and (isinstance(origin, tuple) or len(temp) > 1):
Expand Down
Loading

0 comments on commit a816bb3

Please sign in to comment.