-
Notifications
You must be signed in to change notification settings - Fork 116
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
ast can not parse annotations #353
Comments
Yeah, the AST transformer should not try to parse the second argument of |
Fix released in v4.0.0rc6. |
I'm afraid this is still incompatible with third-party libaries (like jaxtyping). E.g.:
A type annotation can be pretty much anything, after all. |
How is it supposed to tell the difference between forward references and arbitrary arguments then? |
In this particular case I could check for the presence of whitespace, but that's just a stopgap measure. |
Ok, so what about this?
How does a type checker know that |
Perhaps demand that all forward references be entirely strings, e.g. have Alternatively, all I'm really expecting from a typecheck against a user-provided class is FWIW I share your frustration. This always feels like fighting the type system. |
I have lots of uses of forward references within my own apps where I use string forward references only for unresolveable (e.g. typeshed) types. I wouldn't want to declare those invalid.
How would |
perhaps? (Untested) I think that should handle all of |
Actually I think you need a bit more to make Generic and Protocol work, but you get the spirit of it. |
Are you suggesting that typeguard should never eagerly resolve forward references then? That would catastrophically slow down many type checking use cases, as the resolution would have to be done again on every check. |
No. My code snippet above is meant to illustrate when a forward reference should be eagerly resolved. If it's part of a Python built-in If it's part of some other annotation (which can be arbitrary), then it shouldn't be resolved. |
The AST transformer can only see names; those names might not have been defined at that point yet, and might never be (due to guarding by |
Run the snippet I wrote above at decoration time, prior to whatever AST magic you're invoking. I'm not suggesting trying to import any extra modules. I think trying to resolve anything inside |
Hey guys- this might be a dumb idea, but maybe typeguard could allow users to whitelist certain types from forward reference resolution? Maybe something like this? not sure if there's a better way
|
Well, |
Ah I see- a static analysis solution sounds like the way to go. FWIW, the jaxtyping types aren't derived from Perhaps there is a way to implement the policy that Patrick suggested, except with static analysis? It sounds like there's still a question of how you'd want to handle the non-
It seems like the following case could break options 1 and 2, but I'm not sure if something like this would ever come up
Option 3 would solve the above but is an awkward workaround. I'm not sure how option 4 would work. |
FWIW I'm most in favour of option 1. Right now, one of the nice things about jaxtyping is that it's compatible out-of-the-box with essentially any runtime type checker (including typeguard versions strictly less than 3). It just provides the types with the appropriate It would be better not to need conditional imports to try and register jaxtyping with each of N different runtime type-checking libraries. |
Yes, they are, at least in the context of static type checking: https://github.com/google/jaxtyping/blob/main/jaxtyping/indirection.py
Options 1 and 3 don't seem very appealing. Option 2, if made opt-in, would at least be easy to implement while still being a crutch. Option 4 is probably the "right" choice (but requires the most work). Jaxtyping already has such code in place (see above). |
Right, but we're talking about runtime type checking here.
? Anyway, I get the sense that this feature - compatibility with arbitrary user annotations -- is not something you're that interested in. And that's fine, of course, we're all just doing this in our spare time. For now I'll update the jaxtyping docs to recommend beartype only, and we can revisit this if things ever change. |
Option 4 was about having typeguard statically analyze the modules to obtain this information. |
I don't know where you got that from. It's just that I've done a TON of work to get typeguard to even this point, 6 release candidates...and only THEN do I get told that my approach didn't work, and requires a huge amount of extra work. It's a bit mentally exhausting. |
Ah, right! FWIW I think this would defeat much of the advantage of runtime type-checking, in that it allows you to communicate things beyond that which the static type system can express. (In jaxtyping's case, shape and dtype information.)
I sympathize! |
Maybe I'm not following. Static analysis would only be used to obtain information on the types that are to be used in type checks. |
I pretty frequently use
I.e. I believe runtime type checking should not respect the Indeed to my mind this is the whole purpose of runtime type checking: to add additional checks for the things my static type checker (which I use as well) isn't expressive enough to catch. |
That would shut down option 4. What do you think would be the ideal long term solution then? |
So my understanding is that typeguard v4 performs some voodoo magic, parsing AST and modifying it to insert the appropriate type checks (I assume for runtime speed reasons). Meanwhile that typeguard v2 used to (a) perform type checks at the last possible moment, without any processing at decoration time, and (b) used the actual Python objects, not AST. At least on that basis, I think the ideal solution would loosely be something like the following code:
That is: do whatever voodoo is possible to speed things up where possible, but if necessary fall back to the slow-but-correct thing.
|
Hey Patrick, I think this example might be illustrative. (Alex feel free to correct me if I'm wrong) Here is how typeguard currently transforms the code:
Note that if we instead used I think solving issue is a matter of getting typeguard to not rewrite For brevity, here's the desired behavior as I understand (with
I think for option 4, if there were some way to inspect a subscriptable annotation in the ast transformer to determine whether to rewrite its string elements or not, that would work. Maybe it could be some special flag on the |
BTW, I'm down to contribute to both typeguard and jaxtyping to make this happen 🙂 (assuming we want to go that way and you guys are cool with it) |
I would very much like to get some kind of a solution. If you want to contribute, I think you should come up with a concrete plan of action first that I could agree on, to avoid any wasted effort. |
This is establishing a standard that we'd be expecting/asking other runtime typecheckers to follow. This isn't actually necessary, as discussed above. |
All options that don't involve adding extra stack frames are on the table. |
@patrick-kidger that's true. I guess my main argument for doing this is that it's a very natural standard that seems to be implied by the spec. Like I wouldn't be surprised if the typecheckers converged on it. Also afaik, the two main runtime typecheckers are typeguard and beartyping and seems like we could coordinate at this stage. @agronholm the rough plan would be the following
|
Hmm might need to think through this more though. The annotation could contain a callable that returns something else and would need to handle that |
Yeah, this is not a good idea actually. There's a lot of flexibility in how you can use So I think we're back to the original plan (part 3 of the above). Disregard parts 1 and 2. No changes needed on the jaxtyping side. In fact, this fix is about really about handling Edit: I moved something extra I wrote here to a separate issue in jaxtyping because it's unrelated to typeguard. |
Hey @agronholm just wanted to check if you're already working on this. I did an experiment here https://github.com/dkamm/annotated-alias-detector. Let me know if it's along the lines of what you were thinking |
I'm busy with other projects currently. I'll resume work on typeguard in the coming weeks and get a patch release out. If feasible, I'll do what I can about this. |
Bumps [typeguard](https://github.com/agronholm/typeguard) from 3.0.2 to 4.0.0. <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 <https://semver.org/#semantic-versioning-200></code>_.</p> <p><strong>UNRELEASED</strong></p> <ul> <li>Fixed handling of <code>typing_extensions.Literal</code> on Python 3.8 and 3.9 when <code>typing_extensions>=4.6.0</code> is installed (<code>[#363](agronholm/typeguard#363) <https://github.com/agronholm/typeguard/issues/363></code>_; PR by Alex Waygood)</li> <li>Fixed <code>NameError</code> when generated type checking code references an imported name from a method (<code>[#362](agronholm/typeguard#362) <https://github.com/agronholm/typeguard/issues/362></code>_)</li> <li>Fixed docstrings disappearing from instrumented functions (<code>[#359](agronholm/typeguard#359) <https://github.com/agronholm/typeguard/issues/359></code>_)</li> </ul> <p><strong>4.0.0</strong> (2023-05-12)</p> <ul> <li>No changes</li> </ul> <p><strong>4.0.0rc6</strong> (2023-05-07)</p> <ul> <li>Fixed <code>@TypeChecked</code> optimization causing compilation of instrumented code to fail when an <code>if</code> block was left empty by the AST transformer (<code>[#352](agronholm/typeguard#352) <https://github.com/agronholm/typeguard/issues/352></code>_)</li> <li>Fixed the AST transformer trying to parse the second argument of <code>typing.Annotated</code> as a forward reference (<code>[#353](agronholm/typeguard#353) <https://github.com/agronholm/typeguard/issues/353></code>_)</li> </ul> <p><strong>4.0.0rc5</strong> (2023-05-01)</p> <ul> <li>Added <code>InstrumentationWarning</code> to the public API</li> <li>Changed <code>@TypeChecked</code> to skip instrumentation in optimized mode, as in typeguard 2.x</li> <li>Avoid type checks where the types in question are shadowed by local variables</li> <li>Fixed instrumentation using <code>typing.Optional</code> without a subscript when the subscript value was erased due to being an ignored import</li> <li>Fixed <code>TypeError: isinstance() arg 2 must be a type or tuple of types</code> when instrumented code tries to check a value against a naked (<code>str</code>, not <code>ForwardRef</code>) forward reference</li> <li>Fixed instrumentation using the wrong "self" type in the <code>__new__()</code> method</li> </ul> <p><strong>4.0.0rc4</strong> (2023-04-15)</p> <ul> <li>Fixed imports guarded by <code>if TYPE_CHECKING:</code> when used with subscripts (<code>SomeType[...]</code>) being replaced with <code>Any[...]</code> instead of just <code>Any</code></li> <li>Fixed instrumentation inadvertently mutating a function's annotations on Python 3.7 and 3.8</li> <li>Fixed <code>Concatenate[...]</code> in <code>Callable</code> parameters causing <code>TypeError</code> to be raised</li> <li>Fixed type checks for <code>*args</code> or <code>**kwargs</code> not being suppressed when their types are unusable (guarded by <code>if TYPE_CHECKING:</code> or otherwise)</li> </ul> <!-- raw HTML omitted --> </blockquote> <p>... (truncated)</p> </details> <details> <summary>Commits</summary> <ul> <li><a href="https://github.com/agronholm/typeguard/commit/887e27e033ad1adbba009ab7d991a0af985a7290"><code>887e27e</code></a> Declared the latest RC as final</li> <li><a href="https://github.com/agronholm/typeguard/commit/668d2a02bfea49bbf4f0849c6d050ce731843a71"><code>668d2a0</code></a> Added release date</li> <li><a href="https://github.com/agronholm/typeguard/commit/be4dd3350f15ec8b5713e40955dad3f4c9a68ad6"><code>be4dd33</code></a> Don't try to parse the second argument of Annotated as a forward reference</li> <li><a href="https://github.com/agronholm/typeguard/commit/3863c0f494c697e52f124f231a18fc2c172d9538"><code>3863c0f</code></a> Fixed AST transformations potentially leaving "if" bodies empty</li> <li><a href="https://github.com/agronholm/typeguard/commit/a2090ed43c05d514707f2abbe5fb48a4ce144f26"><code>a2090ed</code></a> [pre-commit.ci] pre-commit autoupdate (<a href="https://redirect.github.com/agronholm/typeguard/issues/351">#351</a>)</li> <li><a href="https://github.com/agronholm/typeguard/commit/a6a9b715a753decf120a1bb571815165daa7ebf4"><code>a6a9b71</code></a> Use the proper environment for release</li> <li><a href="https://github.com/agronholm/typeguard/commit/c888515f830ccb4d3f088b44b60bbe105f81d1e6"><code>c888515</code></a> Added release date</li> <li><a href="https://github.com/agronholm/typeguard/commit/8923b7b40e03ebdd874a543e17de9bd865ea9ada"><code>8923b7b</code></a> Made <code>@TypeChecked</code> a no-op in optimized mode (<a href="https://redirect.github.com/agronholm/typeguard/issues/350">#350</a>)</li> <li><a href="https://github.com/agronholm/typeguard/commit/43d686e7306aa285ac8fc94bea45923a354bb7c6"><code>43d686e</code></a> Switch to the official coveralls action</li> <li><a href="https://github.com/agronholm/typeguard/commit/e688da2dc817dc66d042e4f7381d3dc25ee19bcb"><code>e688da2</code></a> Skip type checks where the type names are shadowed by local variables</li> <li>Additional commits viewable in <a href="https://github.com/agronholm/typeguard/compare/3.0.2...4.0.0">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=3.0.2&new-version=4.0.0)](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 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> Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Could this bug be re-open ? Our project is broken by recent version of |
What exactly broke it? Also, there was no consensus on the solution. This would be a major undertaking too. Are you willing to contribute code? |
Basically all projects dependent on One easy fix would be to add some
|
Bumps [typeguard](https://github.com/agronholm/typeguard) from 3.0.2 to 4.0.1. <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 <https://semver.org/#semantic-versioning-200></code>_.</p> <p><strong>4.0.1</strong> (2023-07-27)</p> <ul> <li>Fixed handling of <code>typing_extensions.Literal</code> on Python 3.8 and 3.9 when <code>typing_extensions>=4.6.0</code> is installed (<code>[#363](agronholm/typeguard#363) <https://github.com/agronholm/typeguard/issues/363></code>_; PR by Alex Waygood)</li> <li>Fixed <code>NameError</code> when generated type checking code references an imported name from a method (<code>[#362](agronholm/typeguard#362) <https://github.com/agronholm/typeguard/issues/362></code>_)</li> <li>Fixed docstrings disappearing from instrumented functions (<code>[#359](agronholm/typeguard#359) <https://github.com/agronholm/typeguard/issues/359></code>_)</li> <li>Fixed <code>@TypeChecked</code> failing to instrument functions when there are more than one function within the same scope (<code>[#355](agronholm/typeguard#355) <https://github.com/agronholm/typeguard/issues/355></code>_)</li> <li>Fixed <code>frozenset</code> not being checked (<code>[#367](agronholm/typeguard#367) <https://github.com/agronholm/typeguard/issues/367></code>_)</li> </ul> <p><strong>4.0.0</strong> (2023-05-12)</p> <ul> <li>No changes</li> </ul> <p><strong>4.0.0rc6</strong> (2023-05-07)</p> <ul> <li>Fixed <code>@TypeChecked</code> optimization causing compilation of instrumented code to fail when an <code>if</code> block was left empty by the AST transformer (<code>[#352](agronholm/typeguard#352) <https://github.com/agronholm/typeguard/issues/352></code>_)</li> <li>Fixed the AST transformer trying to parse the second argument of <code>typing.Annotated</code> as a forward reference (<code>[#353](agronholm/typeguard#353) <https://github.com/agronholm/typeguard/issues/353></code>_)</li> </ul> <p><strong>4.0.0rc5</strong> (2023-05-01)</p> <ul> <li>Added <code>InstrumentationWarning</code> to the public API</li> <li>Changed <code>@TypeChecked</code> to skip instrumentation in optimized mode, as in typeguard 2.x</li> <li>Avoid type checks where the types in question are shadowed by local variables</li> <li>Fixed instrumentation using <code>typing.Optional</code> without a subscript when the subscript value was erased due to being an ignored import</li> <li>Fixed <code>TypeError: isinstance() arg 2 must be a type or tuple of types</code> when instrumented code tries to check a value against a naked (<code>str</code>, not <code>ForwardRef</code>) forward reference</li> <li>Fixed instrumentation using the wrong "self" type in the <code>__new__()</code> method</li> </ul> <p><strong>4.0.0rc4</strong> (2023-04-15)</p> <ul> <li>Fixed imports guarded by <code>if TYPE_CHECKING:</code> when used with subscripts (<code>SomeType[...]</code>) being replaced with <code>Any[...]</code> instead of just <code>Any</code></li> <li>Fixed instrumentation inadvertently mutating a function's annotations on Python 3.7</li> </ul> <!-- raw HTML omitted --> </blockquote> <p>... (truncated)</p> </details> <details> <summary>Commits</summary> <ul> <li><a href="https://github.com/agronholm/typeguard/commit/cc5cc54e733d472fda6f805525908e43465a6d05"><code>cc5cc54</code></a> Added release date</li> <li><a href="https://github.com/agronholm/typeguard/commit/2766aa7f8e48fc8da317480f0c478711e05d8ac4"><code>2766aa7</code></a> Install typing_extensions on Python 3.11 too</li> <li><a href="https://github.com/agronholm/typeguard/commit/00ac62195f6c936de4d19465dababb5b06388685"><code>00ac621</code></a> Fixed frozenset not being checked</li> <li><a href="https://github.com/agronholm/typeguard/commit/686f25a9dcc1bd615ea0283b3c3a698bf09a76ac"><code>686f25a</code></a> Bumped the minimum version of typing_extensions</li> <li><a href="https://github.com/agronholm/typeguard/commit/1950db184e966b06129f545c558daf969ef9580e"><code>1950db1</code></a> Updated pre-commit modules</li> <li><a href="https://github.com/agronholm/typeguard/commit/53525e11a3bb1af74f3bd8b3bb62c41408828fd2"><code>53525e1</code></a> Fixed <code>@TypeChecked</code> failing to instrument functions with duplicate names in ...</li> <li><a href="https://github.com/agronholm/typeguard/commit/f377be389765ed0db104b41d78fce3c45e72e149"><code>f377be3</code></a> Fixed deprecation warnings on Python 3.12</li> <li><a href="https://github.com/agronholm/typeguard/commit/91204af820c3e849ecebd88a6da818e7164a1a81"><code>91204af</code></a> Test against Python 3.12</li> <li><a href="https://github.com/agronholm/typeguard/commit/05b1c6727a3302c8b25d909122fffa5901756867"><code>05b1c67</code></a> Fixed docstrings being unavailable after instrumentation</li> <li><a href="https://github.com/agronholm/typeguard/commit/845fcbcbfdaed2bca9704c3ed4adacd33f5ec314"><code>845fcbc</code></a> Fixed NameError when a decorated method references an imported name</li> <li>Additional commits viewable in <a href="https://github.com/agronholm/typeguard/compare/3.0.2...4.0.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=3.0.2&new-version=4.0.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 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> Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
I usually also rely on What I ended up doing as a workaround for
@agronholm, is this a reasonable/reliable workaround for the limitation discussed that @patrick-kidger mentioned in |
I don't quite understand how this would solve the problem. How would Typeguard know, at import time, if it should eagerly resolve the parameters of the annotation, or not? |
Also, was this meant as a workaround in |
Hi @agronholm, this is a workaround for other apps/libraries that use typeguard and relates specifically to a previous comment in this thread: #353 (comment). Maybe it would also be relevant to
Specifically, I am forced to use I was surprised when I noticed
Will output:
This comes as a surprise to me... Since Please note that if I assign the value of
Note that I can run
My previous question ( Footnotes
|
Typeguard statically evaluates the contents of |
I am working on some PoC code that tries to resolve the names to determine if they are safe to unquote or not. |
Bumps [typeguard](https://github.com/agronholm/typeguard) from 3.0.2 to 4.0.0. <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 <https://semver.org/#semantic-versioning-200></code>_.</p> <p><strong>UNRELEASED</strong></p> <ul> <li>Fixed handling of <code>typing_extensions.Literal</code> on Python 3.8 and 3.9 when <code>typing_extensions>=4.6.0</code> is installed (<code>[#363](agronholm/typeguard#363) <https://github.com/agronholm/typeguard/issues/363></code>_; PR by Alex Waygood)</li> <li>Fixed <code>NameError</code> when generated type checking code references an imported name from a method (<code>[#362](agronholm/typeguard#362) <https://github.com/agronholm/typeguard/issues/362></code>_)</li> <li>Fixed docstrings disappearing from instrumented functions (<code>[#359](agronholm/typeguard#359) <https://github.com/agronholm/typeguard/issues/359></code>_)</li> </ul> <p><strong>4.0.0</strong> (2023-05-12)</p> <ul> <li>No changes</li> </ul> <p><strong>4.0.0rc6</strong> (2023-05-07)</p> <ul> <li>Fixed <code>@TypeChecked</code> optimization causing compilation of instrumented code to fail when an <code>if</code> block was left empty by the AST transformer (<code>[#352](agronholm/typeguard#352) <https://github.com/agronholm/typeguard/issues/352></code>_)</li> <li>Fixed the AST transformer trying to parse the second argument of <code>typing.Annotated</code> as a forward reference (<code>[#353](agronholm/typeguard#353) <https://github.com/agronholm/typeguard/issues/353></code>_)</li> </ul> <p><strong>4.0.0rc5</strong> (2023-05-01)</p> <ul> <li>Added <code>InstrumentationWarning</code> to the public API</li> <li>Changed <code>@TypeChecked</code> to skip instrumentation in optimized mode, as in typeguard 2.x</li> <li>Avoid type checks where the types in question are shadowed by local variables</li> <li>Fixed instrumentation using <code>typing.Optional</code> without a subscript when the subscript value was erased due to being an ignored import</li> <li>Fixed <code>TypeError: isinstance() arg 2 must be a type or tuple of types</code> when instrumented code tries to check a value against a naked (<code>str</code>, not <code>ForwardRef</code>) forward reference</li> <li>Fixed instrumentation using the wrong "self" type in the <code>__new__()</code> method</li> </ul> <p><strong>4.0.0rc4</strong> (2023-04-15)</p> <ul> <li>Fixed imports guarded by <code>if TYPE_CHECKING:</code> when used with subscripts (<code>SomeType[...]</code>) being replaced with <code>Any[...]</code> instead of just <code>Any</code></li> <li>Fixed instrumentation inadvertently mutating a function's annotations on Python 3.7 and 3.8</li> <li>Fixed <code>Concatenate[...]</code> in <code>Callable</code> parameters causing <code>TypeError</code> to be raised</li> <li>Fixed type checks for <code>*args</code> or <code>**kwargs</code> not being suppressed when their types are unusable (guarded by <code>if TYPE_CHECKING:</code> or otherwise)</li> </ul> <!-- raw HTML omitted --> </blockquote> <p>... (truncated)</p> </details> <details> <summary>Commits</summary> <ul> <li><a href="https://github.com/agronholm/typeguard/commit/887e27e033ad1adbba009ab7d991a0af985a7290"><code>887e27e</code></a> Declared the latest RC as final</li> <li><a href="https://github.com/agronholm/typeguard/commit/668d2a02bfea49bbf4f0849c6d050ce731843a71"><code>668d2a0</code></a> Added release date</li> <li><a href="https://github.com/agronholm/typeguard/commit/be4dd3350f15ec8b5713e40955dad3f4c9a68ad6"><code>be4dd33</code></a> Don't try to parse the second argument of Annotated as a forward reference</li> <li><a href="https://github.com/agronholm/typeguard/commit/3863c0f494c697e52f124f231a18fc2c172d9538"><code>3863c0f</code></a> Fixed AST transformations potentially leaving "if" bodies empty</li> <li><a href="https://github.com/agronholm/typeguard/commit/a2090ed43c05d514707f2abbe5fb48a4ce144f26"><code>a2090ed</code></a> [pre-commit.ci] pre-commit autoupdate (<a href="https://redirect.github.com/agronholm/typeguard/issues/351">#351</a>)</li> <li><a href="https://github.com/agronholm/typeguard/commit/a6a9b715a753decf120a1bb571815165daa7ebf4"><code>a6a9b71</code></a> Use the proper environment for release</li> <li><a href="https://github.com/agronholm/typeguard/commit/c888515f830ccb4d3f088b44b60bbe105f81d1e6"><code>c888515</code></a> Added release date</li> <li><a href="https://github.com/agronholm/typeguard/commit/8923b7b40e03ebdd874a543e17de9bd865ea9ada"><code>8923b7b</code></a> Made <code>@TypeChecked</code> a no-op in optimized mode (<a href="https://redirect.github.com/agronholm/typeguard/issues/350">#350</a>)</li> <li><a href="https://github.com/agronholm/typeguard/commit/43d686e7306aa285ac8fc94bea45923a354bb7c6"><code>43d686e</code></a> Switch to the official coveralls action</li> <li><a href="https://github.com/agronholm/typeguard/commit/e688da2dc817dc66d042e4f7381d3dc25ee19bcb"><code>e688da2</code></a> Skip type checks where the type names are shadowed by local variables</li> <li>Additional commits viewable in <a href="https://github.com/agronholm/typeguard/compare/3.0.2...4.0.0">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=3.0.2&new-version=4.0.0)](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 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> Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Bumps [typeguard](https://github.com/agronholm/typeguard) from 3.0.2 to 4.0.1. <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 <https://semver.org/#semantic-versioning-200></code>_.</p> <p><strong>4.0.1</strong> (2023-07-27)</p> <ul> <li>Fixed handling of <code>typing_extensions.Literal</code> on Python 3.8 and 3.9 when <code>typing_extensions>=4.6.0</code> is installed (<code>[#363](agronholm/typeguard#363) <https://github.com/agronholm/typeguard/issues/363></code>_; PR by Alex Waygood)</li> <li>Fixed <code>NameError</code> when generated type checking code references an imported name from a method (<code>[#362](agronholm/typeguard#362) <https://github.com/agronholm/typeguard/issues/362></code>_)</li> <li>Fixed docstrings disappearing from instrumented functions (<code>[#359](agronholm/typeguard#359) <https://github.com/agronholm/typeguard/issues/359></code>_)</li> <li>Fixed <code>@TypeChecked</code> failing to instrument functions when there are more than one function within the same scope (<code>[#355](agronholm/typeguard#355) <https://github.com/agronholm/typeguard/issues/355></code>_)</li> <li>Fixed <code>frozenset</code> not being checked (<code>[#367](agronholm/typeguard#367) <https://github.com/agronholm/typeguard/issues/367></code>_)</li> </ul> <p><strong>4.0.0</strong> (2023-05-12)</p> <ul> <li>No changes</li> </ul> <p><strong>4.0.0rc6</strong> (2023-05-07)</p> <ul> <li>Fixed <code>@TypeChecked</code> optimization causing compilation of instrumented code to fail when an <code>if</code> block was left empty by the AST transformer (<code>[#352](agronholm/typeguard#352) <https://github.com/agronholm/typeguard/issues/352></code>_)</li> <li>Fixed the AST transformer trying to parse the second argument of <code>typing.Annotated</code> as a forward reference (<code>[#353](agronholm/typeguard#353) <https://github.com/agronholm/typeguard/issues/353></code>_)</li> </ul> <p><strong>4.0.0rc5</strong> (2023-05-01)</p> <ul> <li>Added <code>InstrumentationWarning</code> to the public API</li> <li>Changed <code>@TypeChecked</code> to skip instrumentation in optimized mode, as in typeguard 2.x</li> <li>Avoid type checks where the types in question are shadowed by local variables</li> <li>Fixed instrumentation using <code>typing.Optional</code> without a subscript when the subscript value was erased due to being an ignored import</li> <li>Fixed <code>TypeError: isinstance() arg 2 must be a type or tuple of types</code> when instrumented code tries to check a value against a naked (<code>str</code>, not <code>ForwardRef</code>) forward reference</li> <li>Fixed instrumentation using the wrong "self" type in the <code>__new__()</code> method</li> </ul> <p><strong>4.0.0rc4</strong> (2023-04-15)</p> <ul> <li>Fixed imports guarded by <code>if TYPE_CHECKING:</code> when used with subscripts (<code>SomeType[...]</code>) being replaced with <code>Any[...]</code> instead of just <code>Any</code></li> <li>Fixed instrumentation inadvertently mutating a function's annotations on Python 3.7</li> </ul> <!-- raw HTML omitted --> </blockquote> <p>... (truncated)</p> </details> <details> <summary>Commits</summary> <ul> <li><a href="https://github.com/agronholm/typeguard/commit/cc5cc54e733d472fda6f805525908e43465a6d05"><code>cc5cc54</code></a> Added release date</li> <li><a href="https://github.com/agronholm/typeguard/commit/2766aa7f8e48fc8da317480f0c478711e05d8ac4"><code>2766aa7</code></a> Install typing_extensions on Python 3.11 too</li> <li><a href="https://github.com/agronholm/typeguard/commit/00ac62195f6c936de4d19465dababb5b06388685"><code>00ac621</code></a> Fixed frozenset not being checked</li> <li><a href="https://github.com/agronholm/typeguard/commit/686f25a9dcc1bd615ea0283b3c3a698bf09a76ac"><code>686f25a</code></a> Bumped the minimum version of typing_extensions</li> <li><a href="https://github.com/agronholm/typeguard/commit/1950db184e966b06129f545c558daf969ef9580e"><code>1950db1</code></a> Updated pre-commit modules</li> <li><a href="https://github.com/agronholm/typeguard/commit/53525e11a3bb1af74f3bd8b3bb62c41408828fd2"><code>53525e1</code></a> Fixed <code>@TypeChecked</code> failing to instrument functions with duplicate names in ...</li> <li><a href="https://github.com/agronholm/typeguard/commit/f377be389765ed0db104b41d78fce3c45e72e149"><code>f377be3</code></a> Fixed deprecation warnings on Python 3.12</li> <li><a href="https://github.com/agronholm/typeguard/commit/91204af820c3e849ecebd88a6da818e7164a1a81"><code>91204af</code></a> Test against Python 3.12</li> <li><a href="https://github.com/agronholm/typeguard/commit/05b1c6727a3302c8b25d909122fffa5901756867"><code>05b1c67</code></a> Fixed docstrings being unavailable after instrumentation</li> <li><a href="https://github.com/agronholm/typeguard/commit/845fcbcbfdaed2bca9704c3ed4adacd33f5ec314"><code>845fcbc</code></a> Fixed NameError when a decorated method references an imported name</li> <li>Additional commits viewable in <a href="https://github.com/agronholm/typeguard/compare/3.0.2...4.0.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=3.0.2&new-version=4.0.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 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> Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
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.0.0rc5
Python version
3.10
What happened?
Typeguard does not support annotations of the form
"a b c"
, which is a format used byjaxtyped
, another library that depends ontypeguard
. Instead,ast
throws an error as it is unable to parse the annotation.How can we reproduce the bug?
Run the code snippet:
Which throws
The text was updated successfully, but these errors were encountered: