Skip to content

add trio240, usage of os.path in async function - #100

Merged
Zac-HD merged 1 commit into
mainfrom
os_path_in_async_function
Jan 16, 2023
Merged

Zac-HD merged 1 commit into
mainfrom
os_path_in_async_function

Conversation

@jakkdl

@jakkdl jakkdl commented Jan 13, 2023

Copy link
Copy Markdown
Member

First bullet point of path manipulation in #58
Suspect this may be overly broad or trigger false alarms, but we'll see.

@jakkdl
jakkdl force-pushed the os_path_in_async_function branch from aa5572e to d9a090e Compare January 13, 2023 12:39
@jakkdl jakkdl mentioned this pull request Jan 13, 2023
10 of 12 tasks
Comment thread flake8_trio.py Outdated
if not self.async_function:
return
func_name = ast.unparse(node.func)
if func_name.startswith("os.path."):

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.

Alas, I suspect that requiring rewrites for all code that calls os.path.join() (and other pure functions) is not going to be viable, so we'll need to read through https://docs.python.org/3/library/os.path.html and work out the list.

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.

Read through the source code, and came up with this list

    safe = (
        "_get_sep",
        "_varprog",
        "_varprogb",
        "normcase",
        "isabs",
        "join",
        "split",
        "splitext",
        "splitdrive",
        "basename",
        "dirname",
        "expanduser",
        "commonpath",
        "expandvars",  # os.fsencode, os.environ, os.fsdecode
        "abspath",  # calls, os.getcwd, which I think python tracks internally?
        "commonprefix",
        "samestat",  # just does simple equality check
        # constants
        "curdir",
        "pardir",
        "extsep",
        "sep",
        "pathsep",
        "defpath",
        "altsep",
        "devnull",
        "supports_unicode_filenames",
    )
    os_funcs = (
        "_path_normpath",
        "normpath",
        "_joinrealpath",
        "islink",
        "lexists",
        "ismount",  # safe on windows, unsafe on posix
        "realpath",
        "exists",
        "isdir",
        "isfile",
        "getatime",
        "getctime",
        "getmtime",
        "getsize",
        "samefile",
        "sameopenfile",
        "relpath",
    )

@jakkdl
jakkdl force-pushed the os_path_in_async_function branch 2 times, most recently from 142ac0a to 32c2706 Compare January 14, 2023 20:17
@jakkdl

jakkdl commented Jan 14, 2023

Copy link
Copy Markdown
Member Author

Updated with explicit list of functions, also realized that looking for imports is easy - and might be somewhat common, so it will now catch that as well.
Rebased on top of main.

@jakkdl
jakkdl force-pushed the os_path_in_async_function branch from 32c2706 to 46b3fef Compare January 14, 2023 20:20
@Zac-HD
Zac-HD merged commit a564160 into main Jan 16, 2023
@jakkdl
jakkdl deleted the os_path_in_async_function branch January 16, 2023 11:37
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