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

Class is not compatible with protocol because some method should be an instance method but it's a static method #498

Closed
2 tasks done
bersbersbers opened this issue Oct 30, 2024 · 1 comment
Labels

Comments

@bersbersbers
Copy link

Things to check first

  • I have searched the existing issues and didn't find my bug already reported there

  • I have checked that my bug is still present in the latest release

Typeguard version

4.4.0

Python version

3.13.0

What happened?

Typeguard says that

typeguard.TypeCheckError: argument "arg" (class code.Class) is not compatible with the Proto protocol because its 'method' method should be an instance method but it's a static method

I think it is wrong saying that.

How can we reproduce the bug?

bug.py

from typeguard import install_import_hook

install_import_hook()

from code import Class, function

function(Class)

code.py

from typing import Protocol


class Proto(Protocol):
    def method(self): ...


class Class(Proto):
    def method(self): ...


def function(arg: type[Proto]): ...

Then run python bug.py.

@agronholm
Copy link
Owner

Ah...checking against a protocol as a class – I think my test suite missed that.

github-actions bot added a commit to Jij-Inc/Playground that referenced this issue Nov 4, 2024
Bumps [typeguard](https://github.com/agronholm/typeguard) from 4.4.0 to
4.4.1.
<details>
<summary>Release notes</summary>
<p><em>Sourced from <a
href="https://github.com/agronholm/typeguard/releases">typeguard's
releases</a>.</em></p>
<blockquote>
<h2>4.4.1</h2>
<ul>
<li>Dropped Python 3.8 support</li>
<li>Changed the signature of <code>typeguard_ignore()</code> to be
compatible with <code>typing.no_type_check()</code> (PR by <a
href="https://github.com/jolaf"><code>@​jolaf</code></a>)</li>
<li>Avoid creating reference cycles when type checking uniontypes and
classes</li>
<li>Fixed checking of variable assignments involving tuple unpacking (<a
href="https://redirect.github.com/agronholm/typeguard/issues/486">#486</a>)</li>
<li>Fixed <code>TypeError</code> when checking a class against
<code>type[Self]</code> (<a
href="https://redirect.github.com/agronholm/typeguard/issues/481">#481</a>)</li>
<li>Fixed checking of protocols on the class level (against
<code>type[SomeProtocol]</code>) (<a
href="https://redirect.github.com/agronholm/typeguard/issues/498">#498</a>)</li>
<li>Fixed <code>Self</code> checks in instance/class methods that have
positional-only arguments</li>
<li>Fixed explicit checks of PEP 604 unions against
<code>types.UnionType</code> (<a
href="https://redirect.github.com/agronholm/typeguard/issues/467">#467</a>)</li>
<li>Fixed checks against annotations wrapped in <code>NotRequired</code>
not being run unless the <code>NotRequired</code> is a forward reference
(<a
href="https://redirect.github.com/agronholm/typeguard/issues/454">#454</a>)</li>
</ul>
</blockquote>
</details>
<details>
<summary>Changelog</summary>
<p><em>Sourced from <a
href="https://github.com/agronholm/typeguard/blob/master/docs/versionhistory.rst">typeguard's
changelog</a>.</em></p>
<blockquote>
<h1>Version history</h1>
<p>This library adheres to
<code>Semantic Versioning 2.0
&lt;https://semver.org/#semantic-versioning-200&gt;</code>_.</p>
<p><strong>4.4.1</strong> (2024-11-03)</p>
<ul>
<li>Dropped Python 3.8 support</li>
<li>Changed the signature of <code>typeguard_ignore()</code> to be
compatible with
<code>typing.no_type_check()</code> (PR by <a
href="https://github.com/jolaf"><code>@​jolaf</code></a>)</li>
<li>Avoid creating reference cycles when type checking uniontypes and
classes</li>
<li>Fixed checking of variable assignments involving tuple unpacking
(<code>[#486](agronholm/typeguard#486)
&lt;https://github.com/agronholm/typeguard/issues/486&gt;</code>_)</li>
<li>Fixed <code>TypeError</code> when checking a class against
<code>type[Self]</code>
(<code>[#481](agronholm/typeguard#481)
&lt;https://github.com/agronholm/typeguard/issues/481&gt;</code>_)</li>
<li>Fixed checking of protocols on the class level (against
<code>type[SomeProtocol]</code>)
(<code>[#498](agronholm/typeguard#498)
&lt;https://github.com/agronholm/typeguard/issues/498&gt;</code>_)</li>
<li>Fixed <code>Self</code> checks in instance/class methods that have
positional-only arguments</li>
<li>Fixed explicit checks of PEP 604 unions against
<code>types.UnionType</code>
(<code>[#467](agronholm/typeguard#467)
&lt;https://github.com/agronholm/typeguard/issues/467&gt;</code>_)</li>
<li>Fixed checks against annotations wrapped in <code>NotRequired</code>
not being run unless the
<code>NotRequired</code> is a forward reference
(<code>[#454](agronholm/typeguard#454)
&lt;https://github.com/agronholm/typeguard/issues/454&gt;</code>_)</li>
</ul>
<p><strong>4.4.0</strong> (2024-10-27)</p>
<ul>
<li>Added proper checking for method signatures in protocol checks
(<code>[#465](agronholm/typeguard#465)
&lt;https://github.com/agronholm/typeguard/pull/465&gt;</code>_)</li>
<li>Fixed basic support for intersection protocols
(<code>[#490](agronholm/typeguard#490)
&lt;https://github.com/agronholm/typeguard/pull/490&gt;</code>_; PR by
<a
href="https://github.com/antonagestam"><code>@​antonagestam</code></a>)</li>
<li>Fixed protocol checks running against the class of an instance and
not the instance
itself (this produced wrong results for non-method member checks)</li>
</ul>
<p><strong>4.3.0</strong> (2024-05-27)</p>
<ul>
<li>Added support for checking against static protocols</li>
<li>Fixed some compatibility problems when running on Python 3.13
(<code>[#460](agronholm/typeguard#460)
&lt;https://github.com/agronholm/typeguard/issues/460&gt;</code>_; PR by
<a
href="https://github.com/JelleZijlstra"><code>@​JelleZijlstra</code></a>)</li>
<li>Fixed test suite incompatibility with pytest 8.2
(<code>[#461](agronholm/typeguard#461)
&lt;https://github.com/agronholm/typeguard/issues/461&gt;</code>_)</li>
<li>Fixed pytest plugin crashing on pytest version older than v7.0.0
(even if it's just
present)
(<code>[#343](agronholm/typeguard#343)
&lt;https://github.com/agronholm/typeguard/issues/343&gt;</code>_)</li>
</ul>
<p><strong>4.2.1</strong> (2023-03-24)</p>
<ul>
<li>Fixed missing <code>typing_extensions</code> dependency for Python
3.12
(<code>[#444](agronholm/typeguard#444)
&lt;https://github.com/agronholm/typeguard/issues/444&gt;</code>_)</li>
<li>Fixed deprecation warning in the test suite on Python 3.13
(<code>[#444](agronholm/typeguard#444)
&lt;https://github.com/agronholm/typeguard/issues/444&gt;</code>_)</li>
</ul>
<!-- raw HTML omitted -->
</blockquote>
<p>... (truncated)</p>
</details>
<details>
<summary>Commits</summary>
<ul>
<li><a
href="https://github.com/agronholm/typeguard/commit/cb42103a35abdfce2737d4eb58ed3d0e7f067b4a"><code>cb42103</code></a>
Added release date</li>
<li><a
href="https://github.com/agronholm/typeguard/commit/b32af0bffb52c0b80f2c781656fb67ae1de87947"><code>b32af0b</code></a>
Added tests against an empty protocol</li>
<li><a
href="https://github.com/agronholm/typeguard/commit/1c53caac1c98e33b113463149c01d835730a814f"><code>1c53caa</code></a>
Fixed <code>pytest_ignore_collect</code> not to block default pytest
code (<a
href="https://redirect.github.com/agronholm/typeguard/issues/464">#464</a>)</li>
<li><a
href="https://github.com/agronholm/typeguard/commit/6d6b4de9940071eacbd83430b3d42207a2ac49ff"><code>6d6b4de</code></a>
Fixed test_raw_uniontype_fail failing on PyPy</li>
<li><a
href="https://github.com/agronholm/typeguard/commit/05a677213cd6cc1f6efac4bc5ed1efcbba67da39"><code>05a6772</code></a>
Fixed checks being skipped for non-forward-reference NotRequired</li>
<li><a
href="https://github.com/agronholm/typeguard/commit/7ff5a51d368b6d23d73c11f8f6da8d64b0c55f3a"><code>7ff5a51</code></a>
Fixed issue links in the changelog</li>
<li><a
href="https://github.com/agronholm/typeguard/commit/b0b20c217331e299c20ab743fbb3dfa4c5eef257"><code>b0b20c2</code></a>
Fixed explicit checks of PEP 604 unions against
<code>types.UnionType</code></li>
<li><a
href="https://github.com/agronholm/typeguard/commit/0a3983039b6f8e0228ba39cb3c682c565ade19d8"><code>0a39830</code></a>
Fixed <code>Self</code> checks when a method has positional-only
arguments</li>
<li><a
href="https://github.com/agronholm/typeguard/commit/eb1e869e2c650db3d1f60a052f1426b52d3fb3cf"><code>eb1e869</code></a>
Fixed reference cycles (<a
href="https://redirect.github.com/agronholm/typeguard/issues/493">#493</a>)</li>
<li><a
href="https://github.com/agronholm/typeguard/commit/28dafeca1b39b8c19217ce09536e349c94734fa8"><code>28dafec</code></a>
Fixed checking of protocols on the class level</li>
<li>Additional commits viewable in <a
href="https://github.com/agronholm/typeguard/compare/4.4.0...4.4.1">compare
view</a></li>
</ul>
</details>
<br />


[![Dependabot compatibility
score](https://dependabot-badges.githubapp.com/badges/compatibility_score?dependency-name=typeguard&package-manager=pip&previous-version=4.4.0&new-version=4.4.1)](https://docs.github.com/en/github/managing-security-vulnerabilities/about-dependabot-security-updates#about-compatibility-scores)

Dependabot will resolve any conflicts with this PR as long as you don't
alter it yourself. You can also trigger a rebase manually by commenting
`@dependabot rebase`.

[//]: # (dependabot-automerge-start)
[//]: # (dependabot-automerge-end)

---

<details>
<summary>Dependabot commands and options</summary>
<br />

You can trigger Dependabot actions by commenting on this PR:
- `@dependabot rebase` will rebase this PR
- `@dependabot recreate` will recreate this PR, overwriting any edits
that have been made to it
- `@dependabot merge` will merge this PR after your CI passes on it
- `@dependabot squash and merge` will squash and merge this PR after
your CI passes on it
- `@dependabot cancel merge` will cancel a previously requested merge
and block automerging
- `@dependabot reopen` will reopen this PR if it is closed
- `@dependabot close` will close this PR and stop Dependabot recreating
it. You can achieve the same result by closing it manually
- `@dependabot show <dependency name> ignore conditions` will show all
of the ignore conditions of the specified dependency
- `@dependabot ignore this major version` will close this PR and stop
Dependabot creating any more for this major version (unless you reopen
the PR or upgrade to it yourself)
- `@dependabot ignore this minor version` will close this PR and stop
Dependabot creating any more for this minor version (unless you reopen
the PR or upgrade to it yourself)
- `@dependabot ignore this dependency` will close this PR and stop
Dependabot creating any more for this dependency (unless you reopen the
PR or upgrade to it yourself)


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

No branches or pull requests

2 participants