Skip to content

Commit

Permalink
Merge pull request #193 from jacebrowning/test-python-3.9
Browse files Browse the repository at this point in the history
Test against Python 3.9
  • Loading branch information
jacebrowning committed Dec 5, 2020
2 parents dd9e11e + 365b8d6 commit ddd7610
Show file tree
Hide file tree
Showing 9 changed files with 62 additions and 40 deletions.
3 changes: 3 additions & 0 deletions .appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ environment:
PYTHON_MINOR: 7
- PYTHON_MAJOR: 3
PYTHON_MINOR: 8
# TODO: Enable this when Python 3.9 is available in the default images
# - PYTHON_MAJOR: 3
# PYTHON_MINOR: 9

cache:
- .venv -> poetry.lock
Expand Down
1 change: 1 addition & 0 deletions .pylint.ini
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ disable=
unsupported-membership-test,
cell-var-from-loop,
cyclic-import,
comparison-with-callable,

init-import=yes

Expand Down
2 changes: 1 addition & 1 deletion .python-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.8.2
3.9.0
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ language: python
python:
- 3.7
- 3.8
- 3.9

cache:
pip: true
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# 0.12 (beta)

- Added `_exclude` parameter to `all()` and `filter()` manager methods to exclude certain objects from loading as a performance optimization.
- Fixed handling of untyped `List`/`Dict` annotations in Python 3.9.

# 0.11.1 (2020-09-12)

Expand Down
14 changes: 11 additions & 3 deletions datafiles/converters/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def map_type(cls, *, name: str = '', item_cls: Optional[type] = None):
if dataclasses.is_dataclass(cls):
converters = {}
for field in dataclasses.fields(cls):
converters[field.name] = map_type(field.type, name=field.name)
converters[field.name] = map_type(field.type, name=field.name) # type: ignore
converter = Dataclass.of_mappings(cls, converters)
log.debug(f'Mapped {cls!r} to new converter: {converter}')
return converter
Expand All @@ -58,9 +58,12 @@ def map_type(cls, *, name: str = '', item_cls: Optional[type] = None):
if cls.__origin__ == list:
try:
converter = map_type(item_cls or cls.__args__[0])
except TypeError as e:
except TypeError as e: # Python 3.8 behavior
assert '~T' in str(e), f'Unhandled error: {e}'
raise TypeError("Type is required with 'List' annotation") from None
except AttributeError as e: # Python 3.9 behavior
assert '__args__' in str(e), f'Unhandled error: {e}'
raise TypeError("Type is required with 'List' annotation") from None
else:
converter = List.of_type(converter)

Expand All @@ -73,11 +76,16 @@ def map_type(cls, *, name: str = '', item_cls: Optional[type] = None):
try:
key = map_type(cls.__args__[0])
value = map_type(cls.__args__[1])
except TypeError as e:
except TypeError as e: # Python 3.8 behavior
assert '~' in str(e), f'Unhandled error: {e}'
raise TypeError(
"Types are required with 'Dict' annotation"
) from None
except AttributeError as e: # Python 3.9 behavior
assert '__args__' in str(e), f'Unhandled error: {e}'
raise TypeError(
"Types are required with 'Dict' annotation"
) from None

converter = Dictionary.of_mapping(key, value)

Expand Down
4 changes: 2 additions & 2 deletions datafiles/mapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ def _infer_attr(name, value):
log.warn(f'{name!r} list type cannot be inferred')
item_cls = Converter
log.debug(f'Inferring {name!r} type: {cls} of {item_cls}')
return map_type(cls, name=name, item_cls=item_cls)
return map_type(cls, name=name, item_cls=item_cls) # type: ignore

if issubclass(cls, dict):
cls.__origin__ = dict
Expand Down Expand Up @@ -290,7 +290,7 @@ def create_mapper(obj, root=None) -> Mapper:
for field in dataclasses.fields(obj):
self_name = f'self.{field.name}'
if pattern is None or self_name not in pattern:
attrs[field.name] = map_type(field.type, name=field.name)
attrs[field.name] = map_type(field.type, name=field.name) # type: ignore

return Mapper(
obj,
Expand Down
69 changes: 38 additions & 31 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 4 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[tool.poetry]

name = "datafiles"
version = "0.12b1"
version = "0.12b2"
description = "File-based ORM for dataclasses."

license = "MIT"
Expand Down Expand Up @@ -32,6 +32,7 @@ classifiers = [
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python",
"Topic :: Software Development",
"Topic :: Utilities",
Expand Down Expand Up @@ -64,8 +65,8 @@ black = "=20.8b1"
isort = "=5.5.1"

# Linters
mypy = "*"
pylint = '~2.6'
mypy = "~0.790"
pylint = { git = "https://github.com/PyCQA/pylint", branch = "master" }
pydocstyle = "*"

# Testing
Expand Down

0 comments on commit ddd7610

Please sign in to comment.