Giter Club home page Giter Club logo

Comments (10)

wu-clan avatar wu-clan commented on May 16, 2024

I am doing this work based on Python 3.8, but even if I add from __future__ Import annotations, I cannot use the | flag either

from fastapi_best_architecture.

wu-clan avatar wu-clan commented on May 16, 2024

Because this is not a library, it must pass local code testing, at least >= 3.7 or 3.8

from fastapi_best_architecture.

wu-clan avatar wu-clan commented on May 16, 2024

Hi, @downdawn

Is it convenient for you to perform the test?

I may lose my coding on May 1st because I don't have a laptop and I can only reply to messages via my phone

from fastapi_best_architecture.

downdawn avatar downdawn commented on May 16, 2024

Using the | symbol to separate is a feature of python3.10+

https://fastapi.tiangolo.com/python-types/#union

image

In the local win environment, I use conda to manage the switching environment, and in the Linux environment, I use pyenv. I can test different python versions.

from fastapi_best_architecture.

wu-clan avatar wu-clan commented on May 16, 2024

Yes, but the library based on 3.10 encoding can run in the lower version. I didn’t find the relevant PEP, so I‘m a little confused.

If just replace Optional to Union, it is very convenient, no-optional

from fastapi_best_architecture.

downdawn avatar downdawn commented on May 16, 2024

python3.10+ can run directly

def process_item(item: int | str):
    print(item, type(item))


if __name__ == '__main__':
    process_item(1)  # 1 <class 'int'>
    process_item("1")  # 1 <class 'str'>

python3.7-3.9 can import from __future__ import annotations run

from fastapi_best_architecture.

downdawn avatar downdawn commented on May 16, 2024

After testing, no_optiona can replace Optional[str] = None with Union[str, None] = None

Can be used in pre-commit.

from fastapi_best_architecture.

wu-clan avatar wu-clan commented on May 16, 2024

python3.10+ can run directly

python3.7-3.9 can import from __future__ import annotations run

Yes, This is expected.

There should be some problems in my submission that caused the error.

from fastapi_best_architecture.

wu-clan avatar wu-clan commented on May 16, 2024

After testing, no_optiona can replace Optional[str] = None with Union[str, None] = None

Can be used in pre-commit.

If we use PEP563, this scheme will not be needed. I have updated it to | through ruff.

from fastapi_best_architecture.

downdawn avatar downdawn commented on May 16, 2024

OK

from fastapi_best_architecture.

Related Issues (20)

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.