Skip to content

Commit

Permalink
made a simple code cleanup
Browse files Browse the repository at this point in the history
better organization with typing and imports

temporary fixed a bug where nullable (or None) values were not accepted in typing.Optional complex objects (such as Tuple)
  • Loading branch information
vltr committed Jun 18, 2019
1 parent 1c90f32 commit 53bb461
Show file tree
Hide file tree
Showing 34 changed files with 308 additions and 325 deletions.
53 changes: 0 additions & 53 deletions .cookiecutterrc

This file was deleted.

1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -67,3 +67,4 @@ docs/_build
.venv
playground.py
requirements.txt
.vscode
4 changes: 0 additions & 4 deletions .vscode/settings.json

This file was deleted.

106 changes: 61 additions & 45 deletions requirements-dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,66 +2,82 @@
# This file is autogenerated by pip-compile
# To update, run:
#
# pip-compile --output-file requirements-dev.txt requirements-dev.in
# pip-compile --output-file=requirements-dev.txt requirements-dev.in
#
alabaster==0.7.11 # via sphinx
alabaster==0.7.12 # via sphinx
apipkg==1.5 # via execnet
appdirs==1.4.3 # via black
argh==0.26.2 # via sphinx-autobuild, watchdog
atomicwrites==1.2.1 # via pytest
attrs==18.2.0 # via black, pytest
babel==2.6.0 # via sphinx
black==18.6b4
atomicwrites==1.3.0 # via pytest
attrs==19.1.0 # via black, pytest
babel==2.7.0 # via sphinx
black==19.3b0
bleach==3.1.0 # via readme-renderer
bumpversion==0.5.3
certifi==2018.8.24 # via requests
certifi==2019.6.16 # via requests
chardet==3.0.4 # via doc8, requests
click==6.7 # via black
coverage==4.5.1
click==7.0 # via black
coverage==4.5.3
doc8==0.8.0
docutils==0.14 # via doc8, restructuredtext-lint, sphinx
execnet==1.5.0 # via pytest-cache
flake8==3.5.0
idna==2.7 # via requests
docutils==0.14 # via doc8, readme-renderer, restructuredtext-lint, sphinx
entrypoints==0.3 # via flake8
execnet==1.6.0 # via pytest-cache
filelock==3.0.12 # via tox
flake8==3.7.7
idna==2.8 # via requests
imagesize==1.1.0 # via sphinx
jinja2==2.10 # via sphinx
livereload==2.5.2 # via sphinx-autobuild
markupsafe==1.0 # via jinja2
importlib-metadata==0.18 # via pluggy, pytest
jinja2==2.10.1 # via sphinx
livereload==2.6.1 # via sphinx-autobuild
markupsafe==1.1.1 # via jinja2
mccabe==0.6.1 # via flake8
more-itertools==4.3.0 # via pytest
packaging==17.1 # via sphinx
more-itertools==7.0.0 # via pytest
packaging==19.0 # via pytest, sphinx
pathtools==0.1.2 # via sphinx-autobuild, watchdog
pbr==4.2.0 # via stevedore
pbr==5.3.0 # via stevedore
pep8==1.7.1 # via pytest-pep8
pkginfo==1.4.2 # via twine
pluggy==0.7.1 # via pytest, tox
pkginfo==1.5.0.1 # via twine
pluggy==0.12.0 # via pytest, tox
port_for==0.3.1 # via sphinx-autobuild
py==1.6.0 # via pytest, tox
pycodestyle==2.3.1
pyflakes==1.6.0 # via flake8, pytest-flakes
pygments==2.2.0
pyparsing==2.2.0 # via packaging
py==1.8.0 # via pytest, tox
pycodestyle==2.5.0
pyflakes==2.1.1 # via flake8, pytest-flakes
pygments==2.4.2
pyparsing==2.4.0 # via packaging
pytest-cache==1.0 # via pytest-pep8
pytest-cov==2.6.0
pytest-cov==2.7.1
pytest-flakes==4.0.0
pytest-pep8==1.0.6
pytest==3.8.0
pytz==2018.5 # via babel
pyyaml==3.13 # via sphinx-autobuild, watchdog
requests-toolbelt==0.8.0 # via twine
requests==2.19.1 # via requests-toolbelt, sphinx, twine
restructuredtext-lint==1.1.3 # via doc8
six==1.11.0 # via doc8, livereload, more-itertools, packaging, pytest, sphinx, stevedore, tox
pytest==4.6.3
pytz==2019.1 # via babel
pyyaml==5.1.1 # via sphinx-autobuild, watchdog
readme-renderer==24.0 # via twine
requests-toolbelt==0.9.1 # via twine
requests==2.22.0 # via requests-toolbelt, sphinx, twine
restructuredtext-lint==1.3.0 # via doc8
six==1.12.0 # via bleach, doc8, livereload, packaging, pytest, readme-renderer, stevedore, tox
snowballstemmer==1.2.1 # via sphinx
sphinx-autobuild==0.7.1
sphinx==1.7.9
sphinxcontrib-websupport==1.1.0 # via sphinx
stevedore==1.29.0 # via doc8
toml==0.9.4 # via black
tornado==5.1 # via livereload, sphinx-autobuild
tox==3.2.1
tqdm==4.25.0 # via twine
twine==1.11.0
urllib3==1.23 # via requests
virtualenv==16.0.0 # via tox
sphinx==2.1.1
sphinxcontrib-applehelp==1.0.1 # via sphinx
sphinxcontrib-devhelp==1.0.1 # via sphinx
sphinxcontrib-htmlhelp==1.0.2 # via sphinx
sphinxcontrib-jsmath==1.0.1 # via sphinx
sphinxcontrib-qthelp==1.0.2 # via sphinx
sphinxcontrib-serializinghtml==1.1.3 # via sphinx
stevedore==1.30.1 # via doc8
toml==0.10.0 # via black, tox
tornado==6.0.2 # via livereload, sphinx-autobuild
tox==3.12.1
tqdm==4.32.1 # via twine
twine==1.13.0
urllib3==1.25.3 # via requests
virtualenv==16.6.1 # via tox
watchdog==0.9.0 # via sphinx-autobuild
wheel==0.31.1
wcwidth==0.1.7 # via pytest
webencodings==0.5.1 # via bleach
wheel==0.33.4
zipp==0.5.1 # via importlib-metadata

# The following packages are considered to be unsafe in a requirements file:
# setuptools==41.0.1 # via sphinx, tox, twine
8 changes: 4 additions & 4 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
# This file is autogenerated by pip-compile
# To update, run:
#
# pip-compile --output-file requirements.txt setup.py
# pip-compile
#
attrs==18.2.0
python-dateutil==2.7.3
six==1.11.0 # via python-dateutil
attrs==19.1.0
python-dateutil==2.8.0
six==1.12.0 # via python-dateutil
15 changes: 9 additions & 6 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
[bdist_wheel]
universal = 1
universal = 0

[flake8]
max-line-length = 79
ignore=E501,W503,C901
ignore=E203,E501,W503
exclude =
*/benchmarks/*

Expand All @@ -29,11 +29,14 @@ addopts =
--tb=short

[isort]
force_single_line = True
line_length = 79
atomic = true
default_section = THIRDPARTY
include_trailing_comma = true
known_first_party = middle
known_third_party = attr,pytest
default_section = THIRDPARTY
forced_separate = test_middle
line_length = 79
lines_after_imports = 2
lines_between_types = 1
multi_line_output = 3
not_skip = __init__.py
skip = benchmarks
11 changes: 4 additions & 7 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
import io
import re

from glob import glob
from os.path import basename
from os.path import dirname
from os.path import join
from os.path import splitext
from os.path import basename, dirname, join, splitext

from setuptools import find_packages
from setuptools import setup
from setuptools import find_packages, setup


def read(*names, **kwargs):
Expand Down Expand Up @@ -62,7 +59,7 @@ def read(*names, **kwargs):
"customizable",
"utilities",
],
install_requires=["attrs>=18", "python-dateutil>=2.6.0"],
install_requires=["attrs>=19.1.0", "python-dateutil>=2.8.0"],
extras_require={
# eg:
# 'rst': ['docutils>=0.11'],
Expand Down
17 changes: 5 additions & 12 deletions src/middle/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,15 @@

import logging

from . import converters
from . import exceptions
from . import model
from . import options
from . import validators
from . import values
from .compat import TypeRegistry
from .compat import get_type
from . import converters, exceptions, model, options, validators, values
from .compat import TypeRegistry, get_type
from .config import config
from .converters import converter
from .dispatch import type_dispatch
from .model import Model
from .model import field
from .model import Model, field
from .validators import validate
from .values import asdict
from .values import value_of
from .values import asdict, value_of


logging.getLogger(__name__).addHandler(logging.NullHandler())

Expand Down
6 changes: 2 additions & 4 deletions src/middle/compat/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
from .types import NoneType
from .types import RegexPatternType
from .types import TypeRegistry
from .types import get_type
from .types import NoneType, RegexPatternType, TypeRegistry, get_type


__all__ = ("get_type", "NoneType", "RegexPatternType", "TypeRegistry")
19 changes: 10 additions & 9 deletions src/middle/compat/types.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import re
import sys
import typing
from datetime import date
from datetime import datetime
import typing as t

from datetime import date, datetime
from decimal import Decimal
from enum import EnumMeta
from functools import lru_cache


_IS_PY36 = False
RegexPatternType = None
if sys.version_info[:2] >= (3, 7):
Expand Down Expand Up @@ -38,11 +39,11 @@ def get_type(type_):
date,
datetime,
Decimal,
typing.Dict,
typing.List,
typing.Set,
typing.Tuple,
typing.Union,
t.Dict,
t.List,
t.Set,
t.Tuple,
t.Union,
):
return type_

Expand All @@ -54,7 +55,7 @@ def get_type(type_):
return type_.__origin__
else: # py37
if hasattr(type_, "_name") and isinstance(type_._name, str):
return getattr(typing, type_._name)
return getattr(t, type_._name)
return type_.__origin__
elif tt == EnumMeta:
return tt
Expand Down
2 changes: 2 additions & 0 deletions src/middle/config.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import logging

from contextlib import contextmanager
from functools import partial

import attr


logger = logging.getLogger(__name__)


Expand Down
Loading

0 comments on commit 53bb461

Please sign in to comment.