Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Update documentation regarding PEP 681 support with mypy #9463

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

Closed
wants to merge 3 commits into from
Closed

Update documentation regarding PEP 681 support with mypy #9463

wants to merge 3 commits into from

Conversation

Viicos
Copy link
Contributor

@Viicos Viicos commented Mar 9, 2023

See https://mypy-lang.blogspot.com/2023/03/mypy-111-released.html
This also fixes a small typo

Description

Checklist

This pull request is:

  • A documentation / typographical error fix
    • Good to go, no issue or tests are needed
  • A short code fix
    • please include the issue number, and create an issue if none exists, which
      must include a complete example of the issue. one line code fixes without an
      issue and demonstration will not be accepted.
    • Please include: Fixes: #<issue number> in the commit message
    • please include tests. one line code fixes without tests will not be accepted.
  • A new feature implementation
    • please include the issue number, and create an issue if none exists, which must
      include a complete example of how the feature would look.
    • Please include: Fixes: #<issue number> in the commit message
    • please include tests.

Have a nice day!

.. note:: Support for :pep:`681` in typing tools as of **July 3, 2022** is
limited and is currently known to be supported by Pyright_, but not yet
.. note:: Support for :pep:`681` in typing tools as of **March 6, 2023** is
limited and is currently known to be fully supported by Pyright_ and
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would take the word "limited" out , at this point

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

indeed.

as of March 9, 2023 is currently known to be fully supported

(btw today it's the 9th :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

indeed.

as of March 9, 2023 is currently known to be fully supported

(btw today it's the 9th :)

I've added 6th as it was the release date of mypy 1.1.1 ;), but I could change to today as well

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

either one is fine. we could also use just the month. It's there just to give a general feel for time when the statement was written/updated

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we can let this poor submitter go free, it's fine

@Viicos
Copy link
Contributor Author

Viicos commented Mar 9, 2023

While I'm on this issue I encountered something weird while working with dataclasses: does column definition order matters when defining models? With the following one:

class Model(Base):
    __tablename__ = "model"

    id: Mapped[int] = mapped_column(primary_key=True, init=False)
    uuid: Mapped[UUID] = mapped_column(default=None, insert_default=uuid4)
    name: Mapped[str] = mapped_column(
        String(255), doc="Name of the model", comment="Name of the model"
    )
    schemas: Mapped[List["Schema"]] = relationship(
        back_populates="model",
        doc="List of linked schemas",
    )

I get the following error: TypeError: non-default argument 'name' follows default argument. This can be fixed by moving the uuid attribute under the schemas one. Is this how it's supposed to be? I can't find anything related to this in the doc.

Edit: this behavior seems to come from the Python dataclass itself. Do you think this could be added in the docs for clarification?

@zzzeek zzzeek requested a review from sqla-tester March 9, 2023 22:44
Copy link
Collaborator

@sqla-tester sqla-tester left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, this is sqla-tester setting up my work on behalf of zzzeek to try to get revision 27ecc83 of this pull request into gerrit so we can run tests and reviews and stuff

@sqla-tester
Copy link
Collaborator

New Gerrit review created for change 27ecc83: https://gerrit.sqlalchemy.org/c/sqlalchemy/sqlalchemy/+/4503

@CaselIT
Copy link
Member

CaselIT commented Mar 9, 2023

Edit: this behavior seems to come from the Python dataclass itself. Do you think this could be added in the docs for clarification?

I think it's implied by the docs, since all that logic is delegated to dataclasses. but I guess we could add a note here so that it gets mentioned #9410

@sqla-tester
Copy link
Collaborator

Federico Caselli (CaselIT) wrote:

depending on what #9467 turns out to be, mypy may not yet correctly support this pep

View this in Gerrit at https://gerrit.sqlalchemy.org/c/sqlalchemy/sqlalchemy/+/4503

Copy link
Member

@zzzeek zzzeek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

turns out we are wrong. mypy has included pep-681 but they did not fix all issues with it, including the main issue that SQLAlchemy needs for it to work.

See python/mypy#13856 , #9467 , python/mypy#14868 .

So while this PR was to be celebratory, it instead needs to be a "if using mypy 1.1.1, you will need to install "type ignores" for all constructors, or stay on mypy 1.0.0 in the interim" :( or something else. not really sure

@Viicos
Copy link
Contributor Author

Viicos commented Mar 10, 2023

Nice catch, my mistake I only trusted the mypy's changelog, and did not apply mypy yet on a project I'm working on after switching to MappedAsDataclass. But I think it's fine to wait until a new fix release is issued before merging this one, hoping it won't take that long :)

@sqla-tester
Copy link
Collaborator

mike bayer (zzzeek) wrote:

we need to wait on this until mypy fixes python/mypy#13856

View this in Gerrit at https://gerrit.sqlalchemy.org/c/sqlalchemy/sqlalchemy/+/4503

@CaselIT
Copy link
Member

CaselIT commented Mar 14, 2023

I guess this could be closed at least unlit mypy fixes its implementation of pep 681

@Viicos
Copy link
Contributor Author

Viicos commented Mar 14, 2023

It can, as 3a47052 has been added since

@Viicos Viicos closed this Mar 14, 2023
@CaselIT
Copy link
Member

CaselIT commented Mar 14, 2023

sorry @Viicos , but thanks for making us look to at mypy ultimately finding this issue.

hopefully we can redo the changes here soon

@sqla-tester
Copy link
Collaborator

Federico Caselli (CaselIT) wrote:

mypy has an issue with pep 681 and it needs to be fixed before merging this change

View this in Gerrit at https://gerrit.sqlalchemy.org/c/sqlalchemy/sqlalchemy/+/4503

@sqla-tester
Copy link
Collaborator

Gerrit review https://gerrit.sqlalchemy.org/c/sqlalchemy/sqlalchemy/+/4503 has been abandoned. That means that at least for the moment I need to close this pull request. Sorry it didn't work out :(

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants