Skip to content

Fix for mypy 1.4 changes#83

Merged
VincentVanlaer merged 6 commits intopython-trio:masterfrom
VincentVanlaer:mypy-1.4
Aug 2, 2023
Merged

Fix for mypy 1.4 changes#83
VincentVanlaer merged 6 commits intopython-trio:masterfrom
VincentVanlaer:mypy-1.4

Conversation

@VincentVanlaer
Copy link
Copy Markdown
Member

@VincentVanlaer VincentVanlaer commented Jun 15, 2023

This PR contains all the necessary changes to the plugin, tests and stubs for mypy 1.4

Api changes

Stubtest changes

As stubtest is part of mypy, and therefore also got updated, the stubs required signficant changes:

List of relevant changes:

  • A whole bunch of types that are final at runtime, are now final in
    for type checking purposes as well
  • Add missing attrs decorators to some types. Internal attrs members
    have been added to the allowlist
  • StrictFIFOLock is no longer a subclass of Lock, as Lock is suposed to
    be final.
  • Converted attributes to read-only properties whenever this was
    necessary to match trio

Minor changes:

  • Ignore internal APIs and tests (previously seemed to be the case by
    default)
  • Typevars and aliases have been prefixed with underscores, so that they
    are not part of the public interface of the modules (as they are not
    available at runtime)

Fixes #84
Fixes #85

@VincentVanlaer VincentVanlaer force-pushed the mypy-1.4 branch 2 times, most recently from e0a930b to d7f402e Compare June 24, 2023 13:52
@VincentVanlaer VincentVanlaer force-pushed the mypy-1.4 branch 3 times, most recently from 80cc7b2 to 1f65b74 Compare June 24, 2023 17:43
List of relevant changes:
- A whole bunch of types that are final at runtime, are now final in
  for type checking purposes as well
- Add missing attrs decorators to some types. Internal attrs members
  have been added to the allowlist
- StrictFIFOLock is no longer a subclass of Lock, as Lock is suposed to
  be final.
- Converted attributes to read-only properties whenever this was
  necessary to match trio

Minor changes:
- Ignore internal APIs and tests (previously seemed to be the case by
  default)
- Typevars and aliases have been prefixed with underscores, so that they
  are not part of the public interface of the modules (as they are not
  available at runtime)
@VincentVanlaer VincentVanlaer marked this pull request as ready for review June 24, 2023 17:54
@VincentVanlaer VincentVanlaer changed the title Fix mypy 1.4 plugin API changes Fix for mypy 1.4 changes Jun 24, 2023
@VincentVanlaer VincentVanlaer requested a review from oremanj July 4, 2023 22:17
@A5rocks
Copy link
Copy Markdown

A5rocks commented Jul 20, 2023

Could you check the mypy version we are passed to choose whether to pass default= or not?

I don't like having to drop mypy < 1.4

@VincentVanlaer VincentVanlaer force-pushed the mypy-1.4 branch 3 times, most recently from 6c273a7 to 01a4c66 Compare July 21, 2023 22:01
Running the tests is not supported on all previous versions of mypy back
to 0.920, but otherwise the plugin should work fine
@VincentVanlaer VincentVanlaer force-pushed the mypy-1.4 branch 2 times, most recently from 9b050c7 to 2adfc8e Compare July 21, 2023 22:09
@VincentVanlaer
Copy link
Copy Markdown
Member Author

I have added a check for the mypy version (and some other required changes due to changes in trio)

Copy link
Copy Markdown

@A5rocks A5rocks left a comment

Choose a reason for hiding this comment

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

Assuming the type changes are correct, this looks fine! I'd like someone who actually knows trio-typing to look at this before merging though :P

Comment thread setup.py
"trio >= 0.16.0",
"typing_extensions >= 3.7.4",
"mypy_extensions >= 0.4.2",
"async_generator",
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Why do you need this backport package?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Because otherwise you have this error: Error importing plugin "trio_typing.plugin": No module named 'async_generator'

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

See #85

FirelightFlagboy added a commit to Scille/parsec-cloud that referenced this pull request Jul 27, 2023
We should be able to bump `mypy` after the PR python-trio/trio-typing#83 is merged
github-merge-queue bot pushed a commit to Scille/parsec-cloud that referenced this pull request Jul 28, 2023
We should be able to bump `mypy` after the PR python-trio/trio-typing#83 is merged
Copy link
Copy Markdown
Member

@jakkdl jakkdl left a comment

Choose a reason for hiding this comment

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

I'm no expert on trio-typing (is anybody?), but seems fine to me.

Copy link
Copy Markdown
Member

@oremanj oremanj left a comment

Choose a reason for hiding this comment

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

Sorry for the delay in looking at this. I'm confused about one of the changes but that doesn't need to block merging.

Comment thread trio-stubs/lowlevel.pyi Outdated
@final
@attr.s(eq=False, hash=False, slots=True)
class RunVar(Generic[_T], metaclass=ABCMeta):
_NO_DEFAULT = object()
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I don't think stubtest should be insisting that we expose underscore-prefixed attributes...

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The idea is that these attributes don't exist in the real thing, but if we say they do in the stubs, typecheckers think that they do exist, which confuses everyone. It is best practice to underscore thinks that don't exist in the real version.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

It's not really stubtest's fault here. It needs these attributes to construct the correct __init__ with attrs. The error only complains about __init__ and __match_args__, not missing attributes. I can remove the _NO_DEFAULT and just inline the object() however.

@VincentVanlaer
Copy link
Copy Markdown
Member Author

Thanks for all the reviews!

@VincentVanlaer VincentVanlaer merged commit 8a1952b into python-trio:master Aug 2, 2023
@VincentVanlaer VincentVanlaer deleted the mypy-1.4 branch August 2, 2023 19:29
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.

Incompatible with trio >= 0.22.1 due to async_generator Breaking change in TypeVarType causes an error during typecheck

7 participants