Skip to content
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

Remove deprecations #582

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
479 changes: 282 additions & 197 deletions CHANGELOG.md

Large diffs are not rendered by default.

9 changes: 0 additions & 9 deletions client_code/augment.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,19 +97,10 @@ def remove_event_handler(component: _Component, event: str, func: _Callable) ->
component.remove_event_handler(event, func)


@deprecated(
"trigger('writeback') is no longer supported\nYou can now trigger a writeback using component.raise_event('x-anvil-write-back-<property>')"
)
def _trigger_writeback(self):
return


def trigger(self: _Component, event: str):
"""trigger an event on a component, self is an anvil component, event is a str or a dictionary
if event is a dictionary it should include an 'event' key e.g. {'event': 'keypress', 'which': 13}
"""
if event == "writeback":
return _trigger_writeback(self)
if isinstance(event, dict):
event = _S.Event(event["event"], event)
event = "mouseenter mouseleave" if event == "hover" else event
Expand Down
24 changes: 5 additions & 19 deletions client_code/messaging.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

from .logging import INFO
from .logging import Logger as _Logger
from .utils._warnings import warn as _warn

__version__ = "3.0.0"

Expand All @@ -31,21 +30,11 @@ def __init__(self, subscriber, handler):
class Publisher:
default_log_level = INFO

def __init__(self, *, logger: _Logger = None, **kwargs):
def __init__(self, *, logger: _Logger = None):
self.logger = logger or _null_logger
self.subscribers = {}
self._deprecation_warnings(**kwargs)

def _deprecation_warnings(self, **kwargs):
if "with_logging" in kwargs:
_warn(
"publisher.with_logging",
"with_logging option is deprecated and it will be removed in future versions. Use the logger options instead, passing an instance of logging.Logger",
"DEPRECATION WARNING",
)

def publish(self, channel, title, content=None, **kwargs):
self._deprecation_warnings(**kwargs)
def publish(self, channel, title, content=None):
message = Message(title, content)
subscribers = self.subscribers.get(channel, [])
for subscriber in subscribers:
Expand All @@ -56,17 +45,15 @@ def publish(self, channel, title, content=None, **kwargs):
f"{len(subscribers)} subscriber(s)",
)

def subscribe(self, channel, subscriber, handler, **kwargs):
self._deprecation_warnings(**kwargs)
def subscribe(self, channel, subscriber, handler):
if channel not in self.subscribers:
self.subscribers[channel] = []
self.subscribers[channel].append(Subscriber(subscriber, handler))
self.logger.log(
self.default_log_level, f"Added subscriber to {channel} channel"
)

def unsubscribe(self, channel, subscriber, **kwargs):
self._deprecation_warnings(**kwargs)
def unsubscribe(self, channel, subscriber):
if channel in self.subscribers:
self.subscribers[channel] = [
s for s in self.subscribers[channel] if s.subscriber != subscriber
Expand All @@ -75,8 +62,7 @@ def unsubscribe(self, channel, subscriber, **kwargs):
self.default_log_level, f"Removed subscriber from {channel} channel"
)

def close_channel(self, channel, **kwargs):
self._deprecation_warnings(**kwargs)
def close_channel(self, channel):
subscribers_count = len(self.subscribers[channel])
del self.subscribers[channel]
self.logger.log(
Expand Down
51 changes: 0 additions & 51 deletions client_code/persistence.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,57 +15,6 @@ def _snakify(text):
return "".join("_" + c.lower() if c.isupper() else c for c in text).lstrip("_")


class LinkedAttribute:
"""A descriptor class for adding linked table items as attributes

For a class backed by a data tables row, this class is used to dyamically add
linked table items as attributes to the parent object.
"""

def __init__(self, linked_column, linked_attr):
"""
Parameters
----------
linked_column: str
The name of the column in the row object which links to another table
linked_attr: str
The name of the column in the linked table which contains the required
value
"""
_warn(
"persistence.LinkedAttribute",
"LinkedAttribute is deprecated and will be removed in future versions. Use a LinkedClass instead.",
"DEPRECATION_WARNING",
)
self._linked_column = linked_column
self._linked_attr = linked_attr

def __set_name__(self, owner, name):
if name == self._linked_column:
raise ValueError(
"Attribute name cannot be the same as the linked column name"
)
self._name = name

def __get__(self, instance, objtype=None):
if instance is None:
return self

if instance._delta:
return instance._delta[self._name]

if not instance._store:
return None

if not instance._store[self._linked_column]:
return None

return instance._store[self._linked_column][self._linked_attr]

def __set__(self, instance, value):
instance._delta[self._name] = value


class LinkedClass:
"A descriptor class for adding objects based on linked tables as attributes"

Expand Down
8 changes: 0 additions & 8 deletions client_code/popover.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,6 @@ def __init__(
delay=None,
max_width=None,
auto_dismiss=True,
dismiss_on_scroll=None,
container=None,
arrow=True,
):
Expand Down Expand Up @@ -277,13 +276,6 @@ def __init__(
self.fake_container = _anvil.Container()
self._clicked = False

if dismiss_on_scroll is not None:
_warn(
"popover.dismiss_on_scroll",
"dismiss_on_scroll option is deprecated",
"DEPRECATION WARNING",
)

self.make_template()
self.add_behavior()

Expand Down
54 changes: 0 additions & 54 deletions client_code/uuid.py

This file was deleted.

2 changes: 1 addition & 1 deletion docs/guides/modules/logging.rst
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ API

# with UID

from anvil_extras.uuid import uuid4
from uuid import uuid4

class UIDLogger(Logger):
def __init__(self, name="uid logger", uid=None, level=INFO, format="{uid}: {msg}"):
Expand Down
26 changes: 2 additions & 24 deletions docs/guides/modules/persistence.rst
Original file line number Diff line number Diff line change
Expand Up @@ -56,28 +56,7 @@ our `book` object will automatically have each of the row's columns as an attrib

But what if we wanted our `book` object to include some information from the author table?

There are two ways to go about that: using a LinkedAttribute or a LinkedClass.

LinkedAttribute
+++++++++++++++
We can use a `LinkedAttribute` to fetch data from the linked row and include it as an
attribute on our object. Let's include the author's name as an attribute of a book:


.. code-block:: python

from anvil_extras.persistence import persisted_class, LinkedAttribute


@persisted_class
class Book:
key = "title"
author_name = LinkedAttribute(linked_column="author", linked_attr="name")


book = Book.get("Fluent Python")

assert book.author_name == "Luciano Ramalho"
There are two ways to go about that: using a LinkedClass.
s-cork marked this conversation as resolved.
Show resolved Hide resolved


LinkedClass
Expand Down Expand Up @@ -112,13 +91,12 @@ display the title and author of the book as a single string:

.. code-block:: python

from anvil_extras.persistence import persisted_class, LinkedAttribute
from anvil_extras.persistence import persisted_class


@persisted_class
class Book:
key = "title"
author_name = LinkedAttribute(linked_column="author", linked_attr="name")

@property
def display_text(self):
Expand Down
2 changes: 1 addition & 1 deletion docs/guides/modules/storage.rst
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ Create an offline todo app
.. code-block:: python

from anvil_extras.storage import indexed_db
from anvil_extras.uuid import uuid4
from uuid import uuid4

todo_store = indexed_db.create_store('todos')
# create_store() is a classmethod that takes a store_name
Expand Down
31 changes: 1 addition & 30 deletions tests/test_persistence.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ def book(book_store):
class Book:
_store = book_store
_delta = {}
author_name = ps.LinkedAttribute(linked_column="author", linked_attr="name")

return Book()

Expand All @@ -30,7 +29,7 @@ def persisted_book():

@ps.persisted_class
class Book:
author_name = ps.LinkedAttribute(linked_column="author", linked_attr="name")
pass

return Book()

Expand All @@ -41,8 +40,6 @@ def customised_book():

@ps.persisted_class
class Book:
author_name = ps.LinkedAttribute(linked_column="author", linked_attr="name")

def save(self):
return "customised save"

Expand Down Expand Up @@ -93,50 +90,24 @@ class Author:
return Author({"name": "Douglas Adams"})


def test_linked_attribute(book, book_store):
"""Test that the LinkedAttribute class works independently of persisted_class"""
assert book.author_name == "Luciano Ramalho"
book.author_name = "Luciano"
assert book._delta["author_name"] == "Luciano"
assert book._store == book_store
assert book.author_name == "Luciano"


def test_linked_attribute_name_clash():
with pytest.raises(RuntimeError) as excinfo:

class Book:
author = ps.LinkedAttribute(linked_column="author", linked_attr="name")

assert "Error calling __set_name__" in str(excinfo.value)


def test_persisted_class_attributes(persisted_book, book_store):
"""Test that persisted class attributes behave as expected"""
persisted_book._store = book_store
assert persisted_book.title == "Fluent Python"
assert persisted_book.author_name == "Luciano Ramalho"
persisted_book.title = "Changed Title"
persisted_book.author_name = "Luciano"
assert persisted_book._delta["title"] == "Changed Title"
assert persisted_book._delta["author_name"] == "Luciano"
assert persisted_book._store == book_store
assert persisted_book.title == "Changed Title"
assert persisted_book.author_name == "Luciano"


def test_persisted_class_indexing(persisted_book, book_store):
"""Test that persisted class also works with index access"""
persisted_book._store = book_store
assert persisted_book["title"] == "Fluent Python"
assert persisted_book["author_name"] == "Luciano Ramalho"
persisted_book["title"] = "Changed Title"
persisted_book["author_name"] = "Luciano"
assert persisted_book._delta["title"] == "Changed Title"
assert persisted_book._delta["author_name"] == "Luciano"
assert persisted_book._store == book_store
assert persisted_book["title"] == "Changed Title"
assert persisted_book["author_name"] == "Luciano"


def test_default_server_functions(persisted_book):
Expand Down