Skip to content

UPath(...) detected as type Any in 0.3.2 #435

@edgarrmondragon

Description

@edgarrmondragon

Probably caused by 023414d

I can reproduce this with

from typing import Any, assert_type

from upath import UPath

params: dict[str, Any] = {}

path = UPath("/foo/bar/baz", protocol="file", **params)
assert_type(path, UPath)

resolved = path.resolve()
assert_type(resolved, UPath)

which mypy doesn't like

$ uv run mypy main.py
main.py:8: error: Expression is of type "Any", not "UPath"  [assert-type]
main.py:11: error: Expression is of type "Any", not "UPath"  [assert-type]
Found 2 errors in 1 file (checked 1 source file)

nor does ty, for good measure

$ uv run ty check main.py
WARN ty is pre-release software and not ready for production use. Expect to encounter bugs, missing features, and fatal errors.
Checking ------------------------------------------------------------ 1/1 files
error[type-assertion-failure]: Argument does not have asserted type `UPath`
  --> main.py:11:1
   |
10 | resolved = path.resolve()
11 | assert_type(resolved, UPath)
   | ^^^^^^^^^^^^--------^^^^^^^^
   |             |
   |             Inferred type of argument is `Unknown`
   |
info: `UPath` and `Unknown` are not equivalent types
info: rule `type-assertion-failure` is enabled by default

Found 1 diagnostic

If I comment out the __new__ overloads in upath/core.py, the variable is revealed to be of type UPath.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug 🐛Something isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions