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

Support standard PEP-484 mechanisms for disregarding type annotations #3231

Open
tedyu002 opened this issue Nov 12, 2019 · 3 comments
Open

Support standard PEP-484 mechanisms for disregarding type annotations #3231

tedyu002 opened this issue Nov 12, 2019 · 3 comments

Comments

@tedyu002
Copy link

@tedyu002 tedyu002 commented Nov 12, 2019

Cython Version: 0.29.14

class Test:
   pass
def test(q:str = Test()):
   pass

After this code is cythonize and running.
The error

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "test.py", line 24, in init test
TypeError: Expected unicode, got Test

appeared.

I have tries the compiler directive but no one can resolve this.

Since it's the usage of the FastAPI to declare the type and produces OpenAPI information.
We cannot ignore the type information.

@app.get("/items/")
async def read_items(q: str = Query(None, max_length=50)):
    results = {"items": [{"item_id": "Foo"}, {"item_id": "Bar"}]}
    if q:
        results.update({"q": q})
    return results

Thanks.

@da-woods

This comment has been minimized.

Copy link
Contributor

@da-woods da-woods commented Nov 12, 2019

#1672

I have tries the compiler directive but no one can resolve this.

I assume you mean #cython: annotation_typing=False? Because it works for me.

@da-woods

This comment has been minimized.

Copy link
Contributor

@da-woods da-woods commented Nov 12, 2019

With that said, annotation_typing wasn't documented so I created a tiny pull request to fix this: #3232

@scoder scoder changed the title Is the type checking can be disabled for the default argument with type hint? Support standard PEP-484 mechanisms for disregarding type annotations Nov 12, 2019
@scoder

This comment has been minimized.

Copy link
Contributor

@scoder scoder commented Nov 12, 2019

Your code example does not comply with PEP-484, unless you use something like # type: ignore. However, Cython does not currently understand this. We should honour the normal PEP-484 mechanisms here for disregarding type annotations.

PR welcome, as always.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants
You can’t perform that action at this time.