Skip to content

21X and 22X, blocking sync calls in async function - #94

Merged
Zac-HD merged 1 commit into
python-trio:mainfrom
jakkdl:58_async_alternatives_blocking_io_calls
Jan 12, 2023
Merged

Zac-HD merged 1 commit into
python-trio:mainfrom
jakkdl:58_async_alternatives_blocking_io_calls

Conversation

@jakkdl

@jakkdl jakkdl commented Dec 31, 2022 •

Copy link
Copy Markdown
Member

Checking off the first couple sync calls in #58

Flake8TrioVisitor.__subclasses__ didn't do it anymore once I started using multilevel inheritance, so solved it by creating a decorator for error classes that registers them. (type hinting the decorator function was fun 😅)

Wasn't sure if the http calls and process invocation bullet points wanted different error messages for each, and the messages themselves are kinda rough, but went with this for a first pass.

TODO:

  • changelog
  • better readme text & error messages
  • os.spawn[vl]p?e? should give TRIO220 sometimes
  • test file shouldn't be called trio210.py - change regex so it can be named trio2xx.py or split into trio21x.py and trio22x.py

Don't bother merging both this and #91, merge one and I'll fix the conflicts in the other.

@jakkdl
jakkdl force-pushed the 58_async_alternatives_blocking_io_calls branch from e742720 to 9a5b9ac Compare January 5, 2023 11:35
@jakkdl
jakkdl marked this pull request as ready for review January 5, 2023 11:35
@jakkdl
jakkdl force-pushed the 58_async_alternatives_blocking_io_calls branch from 9a5b9ac to 14991c7 Compare January 5, 2023 11:37
@jakkdl

jakkdl commented Jan 5, 2023

Copy link
Copy Markdown
Member Author

Not gonna bother composing beautiful error messages and readme texts until the split has been decided on.

@Zac-HD Zac-HD left a comment

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.

Looks good!

Comment thread flake8_trio.py Resolved
Comment thread flake8_trio.py Resolved
Comment thread flake8_trio.py Resolved
@jakkdl
jakkdl force-pushed the 58_async_alternatives_blocking_io_calls branch from 14991c7 to 23eaaf3 Compare January 11, 2023 15:33
@jakkdl jakkdl changed the title first draft of 21X and 22X, blocking sync calls in async function 21X and 22X, blocking sync calls in async function Jan 11, 2023
@jakkdl
jakkdl force-pushed the 58_async_alternatives_blocking_io_calls branch from 23eaaf3 to 73e27fb Compare January 11, 2023 15:34
@jakkdl

jakkdl commented Jan 11, 2023 •

Copy link
Copy Markdown
Member Author

addressed comments, rebased on top of main. This PR is turning out quite meaty indeed.

The documentation and error messages are still mediocre, feel free to suggest changes.

@Zac-HD Zac-HD left a comment •

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 think we need to walk back one heuristic (see below); otherwise looks great - I'm happy with these messages, so if you add the version bump we'll auto-release on merge!

Comment thread flake8_trio.py Outdated
Comment on lines +1534 to +1536
"httpx" in self.imports
and isinstance(node.func, ast.Attribute)
and node.func.attr in http_methods | {"request", "stream", "send"}

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 think this is probably too false-alarm-prone; without the extra evidence from the first argument being a known constant we'll error on any method with one of these extremely common names. For example:

import httpx

some_dict.get(...)  # should not raise a TRIO warning!

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 still has to be inside an async function, and not be awaited. But yeah could also track the variable name a call to httpx.Client() is saved to (and do the same with urllib3), as is currently done with nurseries.

Removed it for now, and bumped version.

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.

It still has to be inside an async function, and not be awaited. But yeah could also track the variable name a call to httpx.Client() is saved to (and do the same with urllib3), as is currently done with nurseries.

Probably a good follow-up PR once we get the other parts of #58 done 👍

@jakkdl
jakkdl force-pushed the 58_async_alternatives_blocking_io_calls branch from 73e27fb to 0ee8303 Compare January 12, 2023 12:07
@Zac-HD
Zac-HD merged commit 60dc59a into python-trio:main Jan 12, 2023
@jakkdl
jakkdl deleted the 58_async_alternatives_blocking_io_calls branch January 12, 2023 13:09
@jakkdl jakkdl mentioned this pull request Jan 12, 2023
10 of 12 tasks
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.

2 participants