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

Not working with python 3.8.2 and from __future__ import annotations #100

Closed
egh opened this issue May 4, 2020 · 1 comment · Fixed by #101
Closed

Not working with python 3.8.2 and from __future__ import annotations #100

egh opened this issue May 4, 2020 · 1 comment · Fixed by #101
Labels
bug Something isn't working in progress This issue is worked on

Comments

@egh
Copy link

egh commented May 4, 2020

To reproduce:

$ mkdir test-jsons
$ cd test-jsons
# Set up dependencies, e.g.
$ cat > pyproject.toml <<EOF
[tool]
[tool.poetry]
name = "test-jsons"
version = "0.0.0"
description = "test jsons"
authors = ["Erik Hetzner"]
[tool.poetry.dependencies]
python = "==3.8.2"
jsons = "*"
EOF
$ poetry install
$ cat > test.py <<EOF
from __future__ import annotations
import jsons
from dataclasses import dataclass
@dataclass
class Foo(object):
    bar: str
print(jsons.dump(Foo('baz')))
EOF
$ poetry run python test.py

Expected output:

{'bar': 'baz'}

Actual output:

/home/egh/.cache/pypoetry/virtualenvs/test-jsons-Z5_mcWPc-py3.8/lib/python3.8/site-packages/jsons/_common_impl.py:42: UserWarning: Failed to dump attribute "baz" of object of type "Foo". Reason: 'NoneType' object is not callable. Ignoring the attribute. You can suppress warnings like this using jsons.suppress_warnings().
  warnings.warn(msg_, *args, **kwargs)
{}

Removing the from __future__ import annotations line fixes the issue.

AddressXception added a commit to Election-Tech-Initiative/electionguard-python that referenced this issue May 4, 2020
__future__ annotations is causing the json serialization to fail.  annotations are necessary to support fluent interface typing for methods on class instances which return their encapsulating type.

see: ramonhagenaars/jsons#26

and ramonhagenaars/jsons#100

until this is fixed, the builder pattern must exist in it's own file
AddressXception added a commit to Election-Tech-Initiative/electionguard-python that referenced this issue May 7, 2020
* 📝 Add VSCode Recommended Extensions

Add recommendations to ensure users know to install python tools.

* 🧹 Configure VSCode Formatting & Linting Settings

- Enable pylint settings and mypy type checking
- Set the formatting to rely on black

* ✅ Configure Pytest for VS Code


__init__ is necessary to ensure tests are run properly.

* 🔧Configure Github PR Workflow

🔧Configure MyPy to match tox file
🔧Add Black Configuration 
🔧Update Pylint configuration

* 📝Update Readme for first time users

- Isolate Contributing file
- Update Readme with usable dev steps

* ✨MacOS Workflow

* 🧹 Add Dev Lint Dependencies to Pipfile

🛠 Allow Prerelease for Black

* 🔧 Add Linting Bypass and Adjustments to MyPy

- MyPy check is silly and needs to have direct directories and files
- Due to errors with last PR some pieces need to temporarily be bypassed.

* Add InternalElectionDescription

generate placeholders for contests when the election is set up.  Use a builder pattern for setting up an election.

* rename Election to ElectionDescription

* Move Election builder to its own file

__future__ annotations is causing the json serialization to fail.  annotations are necessary to support fluent interface typing for methods on class instances which return their encapsulating type.

see: ramonhagenaars/jsons#26

and ramonhagenaars/jsons#100

until this is fixed, the builder pattern must exist in it's own file

* clean up mypy, move proof generation to class objects

* add decrypt contest and decrypt ballot methods

* Create ObjectBase

* decrypt using derivative nonce seeds for the ballot

when decrypting, allow the consumer to specify the nonce seed to use when generating the nonce for decrypting selections.

* proofs are optional on cyphertext resources

add a few missing tests

* remove contest file

* migrate optional handlers to .utils

* update extended data field

* allow nonce values to be null on cyphertext ballot elements

* rename election builder

* nonce seed to elementmodq

* rename election object base

* provide context for integer params

Co-authored-by: Keith Fung <keith.fung@infernored.com>
@ramonhagenaars ramonhagenaars added bug Something isn't working in progress This issue is worked on labels May 10, 2020
@ramonhagenaars
Copy link
Owner

The issue seems to be that when using from __future__ import annotations, the type hints are converted to strings which makes jsons fail to find the right (de)serializer. I consider this a bug and it will be fixed and deployed in the next release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working in progress This issue is worked on
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants