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

[Bug] from __future__ import annotations #26

Closed
jmolinski opened this issue Mar 24, 2019 · 2 comments
Closed

[Bug] from __future__ import annotations #26

jmolinski opened this issue Mar 24, 2019 · 2 comments
Labels
bug Something isn't working

Comments

@jmolinski
Copy link
Contributor

Hello!

from __future__ import annotations literally destroys the library.

Quick example:

foo.py

from __future__ import annotations

from dataclasses import dataclass


@dataclass
class Spam:
    eggs: int


@dataclass
class Baz:
    qux: int
    spam: Spam

bar.py

from typing import List

import jsons

from foo import Baz

data = [{"qux": 0, "spam": {"eggs": 1}}]

x = jsons.load(data, List[Baz])

Expected result: [Baz(qux=0, spam=Spam(eggs=1))]
Result:

>>> import bar
Traceback (most recent call last):
  File "/home/glen/traktpy/venv/lib/python3.7/site-packages/jsons/_main_impl.py", line 146, in load
    return deserializer(json_obj, cls, **kwargs_)
TypeError: 'NoneType' object is not callable

During handling of the above exception, another exception occurred:

Traceback (most recent call last):

...

  File "/home/glen/traktpy/venv/lib/python3.7/site-packages/jsons/_main_impl.py", line 150, in load
    raise DeserializationError(str(err), json_obj, cls)
jsons.exceptions.DeserializationError: 'NoneType' object is not callable
>>> 

If you remove from __future__ import annotations from foo.py everything works as expected.

https://www.python.org/dev/peps/pep-0563/
from __future__ import annotations stops the interpreter from executing type annotations, they are stored as str instead. Types may be revealed during runtime using typing.get_type_hints(). This is going to be the default behavior in python4.

@ramonhagenaars
Copy link
Owner

Hello jmolinsky. This looks serious, thank you for reporting it.

@ramonhagenaars ramonhagenaars added the bug Something isn't working label Mar 24, 2019
@ramonhagenaars ramonhagenaars added the in progress This issue is worked on label Mar 31, 2019
@ramonhagenaars
Copy link
Owner

This has been solved in 0.8.4.

@ramonhagenaars ramonhagenaars removed the in progress This issue is worked on label Apr 7, 2019
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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants