Project specific setup issues

Running on Windows 10 with PyCharm 2024.2.1 Professional running Python 3.11.  

I initially set up this project after I'd pulled down the FastAPI course from TalkPython.  I had previous Python dev directory so I imported the course material there.  I then started a project in the ch03-first-api folder.  All seemed to go well but I started noticing a few glitches as I got started.  

First off the requirements.txt file was not recognized as being a source for specifying packages.  I had to specify the packages in the source code before they would install.  Next, while type hints worked (x: int) when I used the Optional keyword it was not recognized until I explicitly imported it.  (from typing import Optional).

Obviously I mucked something up sometime between copying the course work and starting the PyCharm project.  I have no idea what I did or how to correct it and I'm hoping someone in the community can give me a clue.

Thank you,

Ken

0

Not sure about requirements.txt, but `from typing import Optional` is in fact necessary. If your course didn't make that clear, I question the correctness and usefulness of its other material. `Optional` is not a special keyword. `typing.Optional[T]` is just an alias for `typing.Union[T, None]`, which can also be written as `T | None` in recent versions of Python.

As for the rest, you might want to work through this document as a guide to setting up a project: https://www.jetbrains.com/help/pycharm/setting-up-your-project.html

0

Thank you!  I'll review the article and see if I can see where I messed up.

0

请先登录再写评论。