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

inspect.getmodulename accepts pathlib.Path #10328

Closed
jaraco opened this issue Jun 18, 2023 · 0 comments · Fixed by #10329
Closed

inspect.getmodulename accepts pathlib.Path #10328

jaraco opened this issue Jun 18, 2023 · 0 comments · Fixed by #10329

Comments

@jaraco
Copy link
Member

jaraco commented Jun 18, 2023

Consider this simple snippet:

# mod.py
import inspect
import pathlib

inspect.getmodulename(pathlib.PurePosixPath('foo.py'))

Run it with Python 3.8 or later and it runs fine (I don't have Python 3.7 due to ARM).

Check it with mypy and it fails:

 draft $ mypy mod.py
mod.py:4: error: Argument 1 to "getmodulename" has incompatible type "PurePosixPath"; expected "str"  [arg-type]
Found 1 error in 1 file (checked 1 source file)

Indeed the definition indicates that only str is allowed for input.

The implementation passes the input through to os.path.basename, which accepts pathlib.Path. Probably the typeshed should reflect this behavior, especially considering that the docs suggest that the input is a "path".

hauntsaninja added a commit to hauntsaninja/typeshed that referenced this issue Jun 18, 2023
jaraco added a commit to python/importlib_metadata that referenced this issue Aug 20, 2024
clrpackages pushed a commit to clearlinux-pkgs/pypi-importlib_metadata that referenced this issue Aug 22, 2024
…3.0 to version 8.4.0

Daniel Hollas (2):
      Defer import inspect
      Don't use global var

Jason R. Coombs (5):
      Restore single-expression logic.
      Use third-person imperative voice and link to issue in comment.
      Remove workaround for python/typeshed#10328.
      Add news fragment.
      Finalize
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 a pull request may close this issue.

1 participant