Giter Club home page Giter Club logo

typedjson-python's People

Contributors

barnabyshearer avatar ganow avatar mitsuse avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

typedjson-python's Issues

Integers fail to decode as floats

In python static typing, integers are defined as being a subset of floats. In other words, you can do the following and it will not fail a Mypy check:

bar:float = 1.0 #Define bar as a float
bar = 1 #Assign an integer

I believe it is therefore natural to expect a json string given as an integer to not fail to be parsed into a class where the variable has been defined as a float. Take for example the following dataclass that has a single float variable defined:

@dataclass
class FloatVariable():
    var:float = 1.0

Trying to decode the following json string will fail with <DecodingError reason=<TypeMismatch path=('var',)>>:

{
  "var": 1
}

The reason I bring this up is that I have users who will be editing json-files which gets loaded into dataclasses in exactly this manner. There are variables which are defined as floats in the dataclasses, but users are very likely to write them as integers in the json files. It is unreasonable to demand from the users that they never define variables as integers in the json files. After all, there is no difference between 1 and 1.0 from the users perspective.

`decode()` does not save `result.path` variable.

@mitsuse, the decode function (from typedjson/decoding.py) does not save the result.path variable when result is an instance of DecodingError. I don't think this is intended since this produces the following issue. Consider for example this call:

print(typedjson.decode(Tuple[int,int], (1,'2')))

Right now this produces DecodingError(()) while I suppose it should produce DecodingError(('1',)). I think that we should check if the result.path variable was changed and in that case update the path parameter like so:

for d in decoders:
   result = d(type_, json, path)
   if not isinstance(result, DecodingError):
      break
   elif result.path:
      path = result.path

AttributeError: module 'typing' has no attribute '_ClassVar'

I'm getting this error when running a python azure function that uses typedjson package on Python 3.7 and 3.8.
Apparently the exception is caused by the dependency to dataclasses = "^0.6.0" in python >= 3.7.

See this issue:
#konradhalas/dacite#48
#google/flax#269

This is a proposed fix:
#konradhalas/dacite#49
#DataBiosphere/hca-metadata-api@8357cf0

Here is the entire stack trace:
Result: Failure Exception: AttributeError: module 'typing' has no attribute '_ClassVar' Stack: File "/azure-functions-host/workers/python/3.8/LINUX/X64/azure_functions_worker/dispatcher.py", line 262, in _handle__function_load_request func = loader.load_function( File "/azure-functions-host/workers/python/3.8/LINUX/X64/azure_functions_worker/utils/wrappers.py", line 32, in call return func(*args, **kwargs) File "/azure-functions-host/workers/python/3.8/LINUX/X64/azure_functions_worker/loader.py", line 76, in load_function mod = importlib.import_module(fullmodname) File "/usr/local/lib/python3.8/importlib/init.py", line 127, in import_module return _bootstrap._gcd_import(name[level:], package, level) File "", line 1014, in _gcd_import File "", line 991, in _find_and_load File "", line 975, in _find_and_load_unlocked File "", line 671, in _load_unlocked File "", line 783, in exec_module File "", line 219, in _call_with_frames_removed File "/home/site/wwwroot/TelraamScheduler/main.py", line 13, in from ..Common.Telraam.scrape_segment_message import ScrapeSegmentMessage File "/home/site/wwwroot/Common/Telraam/scrape_segment_message.py", line 5, in class ScrapeSegmentMessage(): File "/home/site/wwwroot/.python_packages/lib/site-packages/dataclasses.py", line 958, in dataclass return wrap(_cls) File "/home/site/wwwroot/.python_packages/lib/site-packages/dataclasses.py", line 950, in wrap return _process_class(cls, init, repr, eq, order, unsafe_hash, frozen) File "/home/site/wwwroot/.python_packages/lib/site-packages/dataclasses.py", line 800, in _process_class cls_fields = [_get_field(cls, name, type) File "/home/site/wwwroot/.python_packages/lib/site-packages/dataclasses.py", line 800, in cls_fields = [_get_field(cls, name, type) File "/home/site/wwwroot/.python_packages/lib/site-packages/dataclasses.py", line 659, in _get_field if (_is_classvar(a_type, typing) File "/home/site/wwwroot/.python_packages/lib/site-packages/dataclasses.py", line 550, in _is_classvar return type(a_type) is typing._ClassVar

Here are the dependecies log installed on azure:
2020-07-29T12:31:36.1317512Z ##[section]Starting: Install dependencies
2020-07-29T12:31:36.1324393Z ==============================================================================
2020-07-29T12:31:36.1324711Z Task : Bash
2020-07-29T12:31:36.1324987Z Description : Run a Bash script on macOS, Linux, or Windows
2020-07-29T12:31:36.1325234Z Version : 3.171.1
2020-07-29T12:31:36.1325456Z Author : Microsoft Corporation
2020-07-29T12:31:36.1325787Z Help : https://docs.microsoft.com/azure/devops/pipelines/tasks/utility/bash
2020-07-29T12:31:36.1326148Z ==============================================================================
2020-07-29T12:31:36.2840459Z Generating script.
2020-07-29T12:31:36.2872017Z ========================== Starting Command Output ===========================
2020-07-29T12:31:36.2889718Z [command]/bin/bash --noprofile --norc /home/vsts/work/_temp/d2b8fe8f-7b7e-4b41-8ec8-a516d419af47.sh
2020-07-29T12:31:42.4588411Z Looking in indexes:
2020-07-29T12:31:42.4590870Z Requirement already satisfied: setuptools in ./worker_venv/lib/python3.8/site-packages (41.2.0)
2020-07-29T12:31:42.8960266Z WARNING: You are using pip version 19.2.3, however version 20.2 is available.
2020-07-29T12:31:42.8962114Z You should consider upgrading via the 'pip install --upgrade pip' command.
2020-07-29T12:31:43.3845340Z Collecting azure-functions (from -r azure_functions_scrapers/requirements.txt (line 1))
2020-07-29T12:31:43.9762247Z Downloading https://files.pythonhosted.org/packages/da/ab/4380cf9683fba6412022b2636797445e60ba5d030f1373769a868acedfd1/azure_functions-1.3.0-py3-none-any.whl (120kB)
2020-07-29T12:31:44.0303337Z Collecting requests (from -r azure_functions_scrapers/requirements.txt (line 2))
2020-07-29T12:31:44.3030806Z Downloading https://files.pythonhosted.org/packages/45/1e/0c169c6a5381e241ba7404532c16a21d86ab872c9bed8bdcd4c423954103/requests-2.24.0-py2.py3-none-any.whl (61kB)
2020-07-29T12:31:44.3332093Z Collecting azure-storage-blob (from -r azure_functions_scrapers/requirements.txt (line 3))
2020-07-29T12:31:44.5925547Z Downloading https://files.pythonhosted.org/packages/6d/3d/31614573e8a197db12d8ab47a7fd813f15bd4a4b5c64e85d23b865de5b9b/azure_storage_blob-12.3.2-py2.py3-none-any.whl (280kB)
2020-07-29T12:31:44.6595082Z Collecting azure-core (from -r azure_functions_scrapers/requirements.txt (line 4))
2020-07-29T12:31:44.8010268Z Downloading https://files.pythonhosted.org/packages/8b/00/efb68e2dda82139d732090fc3b7ff47fe6f34724ea7ba31e518a854b15c1/azure_core-1.7.0-py2.py3-none-any.whl (121kB)
2020-07-29T12:31:44.8345051Z Collecting mapbox (from -r azure_functions_scrapers/requirements.txt (line 5))
2020-07-29T12:31:45.1471618Z Downloading https://files.pythonhosted.org/packages/5b/de/8dbc8e6615e2b09159efe698116d652e2d6867c71f5ae86745ff3e495ec5/mapbox-0.18.0-py2.py3-none-any.whl
2020-07-29T12:31:45.1700689Z Collecting geographiclib (from -r azure_functions_scrapers/requirements.txt (line 6))
2020-07-29T12:31:45.3825928Z Downloading https://files.pythonhosted.org/packages/8b/62/26ec95a98ba64299163199e95ad1b0e34ad3f4e176e221c40245f211e425/geographiclib-1.50-py3-none-any.whl
2020-07-29T12:31:45.3948581Z Collecting pandas (from -r azure_functions_scrapers/requirements.txt (line 7))
2020-07-29T12:31:45.8378246Z Downloading https://files.pythonhosted.org/packages/5d/9f/f4c2a0f6f03d3ba95043c616e477926776ed3de7963a80edede7599630de/pandas-1.1.0-cp38-cp38-manylinux1_x86_64.whl (10.3MB)
2020-07-29T12:31:46.6722235Z Collecting protobuf<4,>=3 (from -r azure_functions_scrapers/requirements.txt (line 8))
2020-07-29T12:31:46.9656530Z Downloading https://files.pythonhosted.org/packages/8f/ce/1402286175ca38a02f5bfb8f01c10beaa062bbff60aca9c39cae9818ba41/protobuf-3.12.2-cp38-cp38-manylinux1_x86_64.whl (1.3MB)
2020-07-29T12:31:47.0524402Z Collecting capacity-ai-datadefinitions==0.0.36 (from -r azure_functions_scrapers/requirements.txt (line 9))
2020-07-29T12:31:47.6751131Z Collecting openlocationcode<2,>=1 (from -r azure_functions_scrapers/requirements.txt (line 10))
2020-07-29T12:31:47.8898231Z Downloading https://files.pythonhosted.org/packages/50/e8/9fc58ee30f4f7b1befe190005c3d0d50b472df4bb968dcae1db7fbbf0e2a/openlocationcode-1.0.1.tar.gz
2020-07-29T12:31:48.7315786Z Collecting azure-storage-queue==2.1.0 (from -r azure_functions_scrapers/requirements.txt (line 11))
2020-07-29T12:31:48.8745190Z Downloading https://files.pythonhosted.org/packages/69/08/a0dcde53f9203fa83111e28fc368404c818a8c54c077ae66559b237c9dd4/azure_storage_queue-2.1.0-py2.py3-none-any.whl
2020-07-29T12:31:48.8903240Z Collecting typedjson (from -r azure_functions_scrapers/requirements.txt (line 12))
2020-07-29T12:31:49.1041854Z Downloading https://files.pythonhosted.org/packages/c3/4c/30b63a61089ca91727f5c0be70488954988a20048c89f2a84455f4e798b9/typedjson-0.7.5-py3-none-any.whl
2020-07-29T12:31:49.1163806Z Collecting python-dateutil==2.8.1 (from -r azure_functions_scrapers/requirements.txt (line 13))
2020-07-29T12:31:49.2764178Z Downloading https://files.pythonhosted.org/packages/d4/70/d60450c3dd48ef87586924207ae8907090de0b306af2bce5d134d78615cb/python_dateutil-2.8.1-py2.py3-none-any.whl (227kB)
2020-07-29T12:31:49.2997762Z Collecting freezegun (from -r azure_functions_scrapers/requirements.txt (line 14))
2020-07-29T12:31:49.4698927Z Downloading https://files.pythonhosted.org/packages/17/5d/1b9d6d3c7995fff473f35861d674e0113a5f0bd5a72fe0199c3f254665c7/freezegun-0.3.15-py2.py3-none-any.whl
2020-07-29T12:31:49.4832988Z Collecting certifi>=2017.4.17 (from requests->-r azure_functions_scrapers/requirements.txt (line 2))
2020-07-29T12:31:49.6513271Z Downloading https://files.pythonhosted.org/packages/5e/c4/6c4fe722df5343c33226f0b4e0bb042e4dc13483228b4718baf286f86d87/certifi-2020.6.20-py2.py3-none-any.whl (156kB)
2020-07-29T12:31:49.6655654Z Collecting idna<3,>=2.5 (from requests->-r azure_functions_scrapers/requirements.txt (line 2))
2020-07-29T12:31:49.8764823Z Downloading https://files.pythonhosted.org/packages/a2/38/928ddce2273eaa564f6f50de919327bf3a00f091b5baba8dfa9460f3a8a8/idna-2.10-py2.py3-none-any.whl (58kB)
2020-07-29T12:31:49.8906347Z Collecting chardet<4,>=3.0.2 (from requests->-r azure_functions_scrapers/requirements.txt (line 2))
2020-07-29T12:31:50.0303999Z Downloading https://files.pythonhosted.org/packages/bc/a9/01ffebfb562e4274b6487b4bb1ddec7ca55ec7510b22e4c51f14098443b8/chardet-3.0.4-py2.py3-none-any.whl (133kB)
2020-07-29T12:31:50.0514876Z Collecting urllib3!=1.25.0,!=1.25.1,<1.26,>=1.21.1 (from requests->-r azure_functions_scrapers/requirements.txt (line 2))
2020-07-29T12:31:50.2650674Z Downloading https://files.pythonhosted.org/packages/9f/f0/a391d1463ebb1b233795cabfc0ef38d3db4442339de68f847026199e69d7/urllib3-1.25.10-py2.py3-none-any.whl (127kB)
2020-07-29T12:31:50.2983817Z Collecting msrest>=0.6.10 (from azure-storage-blob->-r azure_functions_scrapers/requirements.txt (line 3))
2020-07-29T12:31:50.4805409Z Downloading https://files.pythonhosted.org/packages/d9/ed/8e1b75721ad983c1672cd968ad3ae374d2e94767edff6f0b72a15dfde933/msrest-0.6.18-py2.py3-none-any.whl (84kB)
2020-07-29T12:31:50.5134796Z Collecting cryptography>=2.1.4 (from azure-storage-blob->-r azure_functions_scrapers/requirements.txt (line 3))
2020-07-29T12:31:51.0699990Z Downloading https://files.pythonhosted.org/packages/ba/91/84a29d6a27fd6dfc21f475704c4d2053d58ed7a4033c2b0ce1b4ca4d03d9/cryptography-3.0-cp35-abi3-manylinux2010_x86_64.whl (2.7MB)
2020-07-29T12:31:51.2471110Z Collecting six>=1.6 (from azure-core->-r azure_functions_scrapers/requirements.txt (line 4))
2020-07-29T12:31:51.4025642Z Downloading https://files.pythonhosted.org/packages/ee/ff/48bde5c0f013094d729fe4b0316ba2a24774b3ff1c52d924a8a4cb04078a/six-1.15.0-py2.py3-none-any.whl
2020-07-29T12:31:51.4121367Z Collecting iso3166 (from mapbox->-r azure_functions_scrapers/requirements.txt (line 5))
2020-07-29T12:31:51.5556056Z Downloading https://files.pythonhosted.org/packages/a0/42/15d2ef2211ddb26deb810a21b084ee6f3d1bc7248e884dcabb5edc04b649/iso3166-1.0.1-py2.py3-none-any.whl
2020-07-29T12:31:51.5652660Z Collecting uritemplate>=2.0 (from mapbox->-r azure_functions_scrapers/requirements.txt (line 5))
2020-07-29T12:31:51.7059854Z Downloading https://files.pythonhosted.org/packages/bf/0c/60d82c077998feb631608dca3cc1fe19ac074e772bf0c24cf409b977b815/uritemplate-3.0.1-py2.py3-none-any.whl
2020-07-29T12:31:51.7175978Z Collecting polyline>=1.3.1 (from mapbox->-r azure_functions_scrapers/requirements.txt (line 5))
2020-07-29T12:31:51.9229993Z Downloading https://files.pythonhosted.org/packages/0c/4a/67edcfd960ff64221782531c867d862acc6a4e85b382a291bcb820dcde72/polyline-1.4.0-py2.py3-none-any.whl
2020-07-29T12:31:51.9329291Z Collecting cachecontrol (from mapbox->-r azure_functions_scrapers/requirements.txt (line 5))
2020-07-29T12:31:52.0871376Z Downloading https://files.pythonhosted.org/packages/18/71/0a9df4206a5dc5ae7609c41efddab2270a2c1ff61d39de7591dc7302ef89/CacheControl-0.12.6-py2.py3-none-any.whl
2020-07-29T12:31:52.1024416Z Collecting boto3>=1.4 (from mapbox->-r azure_functions_scrapers/requirements.txt (line 5))
2020-07-29T12:31:52.5889190Z Downloading https://files.pythonhosted.org/packages/d4/e4/3f163596bc07259b4fca48ef5668d5ad5be330c2b36c7fdadb9e0401745e/boto3-1.14.30-py2.py3-none-any.whl (129kB)
2020-07-29T12:31:52.6164569Z Collecting numpy>=1.15.4 (from pandas->-r azure_functions_scrapers/requirements.txt (line 7))
2020-07-29T12:31:53.2575017Z Downloading https://files.pythonhosted.org/packages/c7/44/e17846ef3601dcb6f118ea447439650e0c35cb4fe60274fbe24214156df2/numpy-1.19.1-cp38-cp38-manylinux2010_x86_64.whl (14.5MB)
2020-07-29T12:31:53.9259514Z Collecting pytz>=2017.2 (from pandas->-r azure_functions_scrapers/requirements.txt (line 7))
2020-07-29T12:31:54.2661653Z Downloading https://files.pythonhosted.org/packages/4f/a4/879454d49688e2fad93e59d7d4efda580b783c745fd2ec2a3adf87b0808d/pytz-2020.1-py2.py3-none-any.whl (510kB)
2020-07-29T12:31:54.3927347Z Requirement already satisfied: setuptools in ./worker_venv/lib/python3.8/site-packages (from protobuf<4,>=3->-r azure_functions_scrapers/requirements.txt (line 8)) (41.2.0)
2020-07-29T12:31:54.3994949Z Collecting azure-common>=1.1.5 (from azure-storage-queue==2.1.0->-r azure_functions_scrapers/requirements.txt (line 11))
2020-07-29T12:31:54.5934730Z Downloading https://files.pythonhosted.org/packages/e5/4d/d000fc3c5af601d00d55750b71da5c231fcb128f42ac95b208ed1091c2c1/azure_common-1.1.25-py2.py3-none-any.whl
2020-07-29T12:31:54.6061271Z Collecting azure-storage-common~=2.1 (from azure-storage-queue==2.1.0->-r azure_functions_scrapers/requirements.txt (line 11))
2020-07-29T12:31:54.7651404Z Downloading https://files.pythonhosted.org/packages/6b/a0/6794b318ce0118d1a4053bdf0149a60807407db9b710354f2b203c2f5975/azure_storage_common-2.1.0-py2.py3-none-any.whl (47kB)
2020-07-29T12:31:54.7851544Z Collecting dataclasses<0.7.0,>=0.6.0 (from typedjson->-r azure_functions_scrapers/requirements.txt (line 12))
2020-07-29T12:31:54.9476015Z Downloading https://files.pythonhosted.org/packages/26/2f/1095cdc2868052dd1e64520f7c0d5c8c550ad297e944e641dbf1ffbb9a5d/dataclasses-0.6-py3-none-any.whl
2020-07-29T12:31:54.9580000Z Collecting typing-extensions<4.0,>=3.7 (from typedjson->-r azure_functions_scrapers/requirements.txt (line 12))
2020-07-29T12:31:55.1535534Z Downloading https://files.pythonhosted.org/packages/0c/0e/3f026d0645d699e7320b59952146d56ad7c374e9cd72cd16e7c74e657a0f/typing_extensions-3.7.4.2-py3-none-any.whl
2020-07-29T12:31:55.1671193Z Collecting requests-oauthlib>=0.5.0 (from msrest>=0.6.10->azure-storage-blob->-r azure_functions_scrapers/requirements.txt (line 3))
2020-07-29T12:31:55.3107025Z Downloading https://files.pythonhosted.org/packages/a3/12/b92740d845ab62ea4edf04d2f4164d82532b5a0b03836d4d4e71c6f3d379/requests_oauthlib-1.3.0-py2.py3-none-any.whl
2020-07-29T12:31:55.3261599Z Collecting isodate>=0.6.0 (from msrest>=0.6.10->azure-storage-blob->-r azure_functions_scrapers/requirements.txt (line 3))
2020-07-29T12:31:55.4673569Z Downloading https://files.pythonhosted.org/packages/9b/9f/b36f7774ff5ea8e428fdcfc4bb332c39ee5b9362ddd3d40d9516a55221b2/isodate-0.6.0-py2.py3-none-any.whl (45kB)
2020-07-29T12:31:55.4817923Z Collecting cffi!=1.11.3,>=1.8 (from cryptography>=2.1.4->azure-storage-blob->-r azure_functions_scrapers/requirements.txt (line 3))
2020-07-29T12:31:55.8624066Z Downloading https://files.pythonhosted.org/packages/b0/38/969cda34369ffca608cc13db7cb522d7712a67bb060e91ddc55c1c2d7b60/cffi-1.14.1-cp38-cp38-manylinux1_x86_64.whl (409kB)
2020-07-29T12:31:55.8919218Z Collecting msgpack>=0.5.2 (from cachecontrol->mapbox->-r azure_functions_scrapers/requirements.txt (line 5))
2020-07-29T12:31:56.0583150Z Downloading https://files.pythonhosted.org/packages/ba/cf/85e60b003ee5e8ba83c36872320f2dc4eca791350910c8dffeab0bd1672c/msgpack-1.0.0-cp38-cp38-manylinux1_x86_64.whl (303kB)
2020-07-29T12:31:56.0830538Z Collecting botocore<1.18.0,>=1.17.30 (from boto3>=1.4->mapbox->-r azure_functions_scrapers/requirements.txt (line 5))
2020-07-29T12:31:56.7463144Z Downloading https://files.pythonhosted.org/packages/62/94/f9582e581f2ca44e163da99532a8227a3c52530bb3921a27c47f522cb936/botocore-1.17.30-py2.py3-none-any.whl (6.4MB)
2020-07-29T12:31:57.2383361Z Collecting s3transfer<0.4.0,>=0.3.0 (from boto3>=1.4->mapbox->-r azure_functions_scrapers/requirements.txt (line 5))
2020-07-29T12:31:57.3850346Z Downloading https://files.pythonhosted.org/packages/69/79/e6afb3d8b0b4e96cefbdc690f741d7dd24547ff1f94240c997a26fa908d3/s3transfer-0.3.3-py2.py3-none-any.whl (69kB)
2020-07-29T12:31:57.4302314Z Collecting jmespath<1.0.0,>=0.7.1 (from boto3>=1.4->mapbox->-r azure_functions_scrapers/requirements.txt (line 5))
2020-07-29T12:31:57.6212818Z Downloading https://files.pythonhosted.org/packages/07/cb/5f001272b6faeb23c1c9e0acc04d48eaaf5c862c17709d20e3469c6e0139/jmespath-0.10.0-py2.py3-none-any.whl
2020-07-29T12:31:57.6337435Z Collecting oauthlib>=3.0.0 (from requests-oauthlib>=0.5.0->msrest>=0.6.10->azure-storage-blob->-r azure_functions_scrapers/requirements.txt (line 3))
2020-07-29T12:31:57.7899951Z Downloading https://files.pythonhosted.org/packages/05/57/ce2e7a8fa7c0afb54a0581b14a65b56e62b5759dbc98e80627142b8a3704/oauthlib-3.1.0-py2.py3-none-any.whl (147kB)
2020-07-29T12:31:57.8210471Z Collecting pycparser (from cffi!=1.11.3,>=1.8->cryptography>=2.1.4->azure-storage-blob->-r azure_functions_scrapers/requirements.txt (line 3))
2020-07-29T12:31:57.9538778Z Downloading https://files.pythonhosted.org/packages/ae/e7/d9c3a176ca4b02024debf82342dab36efadfc5776f9c8db077e8f6e71821/pycparser-2.20-py2.py3-none-any.whl (112kB)
2020-07-29T12:31:57.9697762Z Collecting docutils<0.16,>=0.10 (from botocore<1.18.0,>=1.17.30->boto3>=1.4->mapbox->-r azure_functions_scrapers/requirements.txt (line 5))
2020-07-29T12:31:58.1173912Z Downloading https://files.pythonhosted.org/packages/22/cd/a6aa959dca619918ccb55023b4cb151949c64d4d5d55b3f4ffd7eee0c6e8/docutils-0.15.2-py3-none-any.whl (547kB)
2020-07-29T12:31:58.3191857Z Installing collected packages: azure-functions, certifi, idna, chardet, urllib3, requests, oauthlib, requests-oauthlib, six, isodate, msrest, pycparser, cffi, cryptography, azure-core, azure-storage-blob, iso3166, uritemplate, polyline, python-dateutil, msgpack, cachecontrol, docutils, jmespath, botocore, s3transfer, boto3, mapbox, geographiclib, numpy, pytz, pandas, protobuf, capacity-ai-datadefinitions, openlocationcode, azure-common, azure-storage-common, azure-storage-queue, dataclasses, typing-extensions, typedjson, freezegun
2020-07-29T12:32:07.2638344Z Running setup.py install for openlocationcode: started
2020-07-29T12:32:07.5971977Z Running setup.py install for openlocationcode: finished with status 'done'
2020-07-29T12:32:07.7348544Z Successfully installed azure-common-1.1.25 azure-core-1.7.0 azure-functions-1.3.0 azure-storage-blob-12.3.2 azure-storage-common-2.1.0 azure-storage-queue-2.1.0 boto3-1.14.30 botocore-1.17.30 cachecontrol-0.12.6 capacity-ai-datadefinitions-0.0.36 certifi-2020.6.20 cffi-1.14.1 chardet-3.0.4 cryptography-3.0 dataclasses-0.6 docutils-0.15.2 freezegun-0.3.15 geographiclib-1.50 idna-2.10 iso3166-1.0.1 isodate-0.6.0 jmespath-0.10.0 mapbox-0.18.0 msgpack-1.0.0 msrest-0.6.18 numpy-1.19.1 oauthlib-3.1.0 openlocationcode-1.0.1 pandas-1.1.0 polyline-1.4.0 protobuf-3.12.2 pycparser-2.20 python-dateutil-2.8.1 pytz-2020.1 requests-2.24.0 requests-oauthlib-1.3.0 s3transfer-0.3.3 six-1.15.0 typedjson-0.7.5 typing-extensions-3.7.4.2 uritemplate-3.0.1 urllib3-1.25.10
2020-07-29T12:32:07.9797064Z WARNING: You are using pip version 19.2.3, however version 20.2 is available.
2020-07-29T12:32:07.9798382Z You should consider upgrading via the 'pip install --upgrade pip' command.
2020-07-29T12:32:08.0404274Z
2020-07-29T12:32:08.0468437Z ##[section]Finishing: Install dependencies

Decoding None as some iterable types raises runtime error

Hi, thank you for providing a great package!
I found that when we try to decode None as List[str], typedjson.decode() raises a runtime error. I think this behavior is unexpected and typedjson.decode() should return either the TypeMismatch error or the decoded result with an empty list.

$ cat example.py
from typing import List
import typedjson

json = None
print(typedjson.decode(List[str], json))

$ poetry run python example.py
Traceback (most recent call last):
  File "example.py", line 5, in <module>
    print(typedjson.decode(List[str], json))
  File "/Users/ny/local/src/github.com/mitsuse/typedjson-python/typedjson/decoding.py", line 90, in decode
    result = d(type_, json, path)
  File "/Users/ny/local/src/github.com/mitsuse/typedjson-python/typedjson/decoding.py", line 225, in decode_as_list
    for index, element in enumerate(json):
TypeError: 'NoneType' object is not iterable

This behavior can be problematic in situations such as the following: if we are expecting some list and no key for that list is given.

@dataclass(frozen=True)
class Person:
    name: str
    skills: List[str]

data = {'name': 'Taro', 'skill': ['C', 'Python']}  # the key specification of the received input has a typo.
person = typedjson.decode(Person, data)  # raises a runtime error!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.