Skip to content

Commit

Permalink
fix: "Type[type]" is incompatible with "Type[property]" (#14)
Browse files Browse the repository at this point in the history
* update .gitignore

* fix misspelled  words

* fix: "Type[type]" is incompatible with "Type[property]"
  • Loading branch information
vitalogy authored Jul 24, 2023
1 parent 3c0d2f3 commit aea1c63
Show file tree
Hide file tree
Showing 2 changed files with 108 additions and 16 deletions.
99 changes: 97 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# C extensions
*.so

# Distribution / packaging
.Python
env/
build/
develop-eggs/
dist/
Expand All @@ -19,9 +19,12 @@ lib64/
parts/
sdist/
var/
wheels/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST

# PyInstaller
# Usually these files are written by a python script from a template
Expand All @@ -36,22 +39,114 @@ pip-delete-this-directory.txt
# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*,cover
*.cover
*.py,cover
.hypothesis/
.pytest_cache/
cover/

# Translations
*.mo
*.pot

# Django stuff:
*.log
local_settings.py
db.sqlite3
db.sqlite3-journal

# Flask stuff:
instance/
.webassets-cache

# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/

# PyBuilder
.pybuilder/
target/

# Jupyter Notebook
.ipynb_checkpoints

# IPython
profile_default/
ipython_config.py

# pyenv
# For a library or package, you might want to ignore these files since the code is
# intended to run in multiple environments; otherwise, check them in:
# .python-version

# pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
# However, in case of collaboration, if having platform-specific dependencies or dependencies
# having no cross-platform support, pipenv may install dependencies that don't work, or not
# install all needed dependencies.
#Pipfile.lock

# poetry
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
# This is especially recommended for binary packages to ensure reproducibility, and is more
# commonly ignored for libraries.
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
#poetry.lock

# PEP 582; used by e.g. github.com/David-OConnor/pyflow
__pypackages__/

# Celery stuff
celerybeat-schedule
celerybeat.pid

# SageMath parsed files
*.sage.py

# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/

# Spyder project settings
.spyderproject
.spyproject

# Rope project settings
.ropeproject

# mkdocs documentation
/site

# mypy
.mypy_cache/
.dmypy.json
dmypy.json

# Pyre type checker
.pyre/

# pytype static type analyzer
.pytype/

# Cython debug symbols
cython_debug/

# PyCharm
# JetBrains specific template is maintainted in a separate JetBrains.gitignore that can
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
# and can be added to the global gitignore or merged into this file. For a more nuclear
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
#.idea/
25 changes: 11 additions & 14 deletions tinydb_serialization/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,11 @@ class Serializer(ABC):
"""
The abstract base class for Serializers.
Allows TinyDB to handle arbitrary objects by running them through a list
of registerd serializers.
of registered serializers.
Every serializer has to tell which class it can handle.
"""

@property
@abstractmethod
def OBJ_CLASS(self):
raise NotImplementedError('To be overriden!')
OBJ_CLASS: object

@abstractmethod
def encode(self, obj):
Expand All @@ -29,7 +26,7 @@ def encode(self, obj):
:return:
:rtype: str
"""
raise NotImplementedError('To be overriden!')
raise NotImplementedError('To be overridden!')

@abstractmethod
def decode(self, s):
Expand All @@ -39,7 +36,7 @@ def decode(self, s):
:type s: str
:return:
"""
raise NotImplementedError('To be overriden!')
raise NotImplementedError('To be overridden!')


def _enumerate_element(element):
Expand Down Expand Up @@ -94,20 +91,20 @@ def _encode_deep(element, serializer, tag, obj_class):
_encode_deep(value, serializer, tag, obj_class)


def has_encodable(element, obj_class):
def has_encodeable(element, obj_class):
"""
Check whether the element in question has an encodable item.
Check whether the element in question has an encodeable item.
"""

found_encodable = False
found_encodeable = False

for key, value in _enumerate_element(element):
if isinstance(value, (dict, list, tuple)):
found_encodable |= has_encodable(value, obj_class)
found_encodeable |= has_encodeable(value, obj_class)
else:
found_encodable |= isinstance(value, obj_class)
found_encodeable |= isinstance(value, obj_class)

return found_encodable
return found_encodeable


class SerializationMiddleware(Middleware):
Expand Down Expand Up @@ -177,7 +174,7 @@ def write(self, data):

for eid in table:
# Before writing, copy data if we haven't already.
if not data_copied and has_encodable(data[table_name][eid],
if not data_copied and has_encodeable(data[table_name][eid],
obj_class):
data = deepcopy(data)
data_copied = True
Expand Down

0 comments on commit aea1c63

Please sign in to comment.