Skip to content

Use imports to collect (scoped) type information #63

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

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

lagru
Copy link
Member

@lagru lagru commented Jul 17, 2025

Closes #20.

This makes it possible to use symbols made available via "from imports" within the same module. This lessens the need to declare types manually.

E.g.

from calendar import January as Jan, Day

def last_day(m):
    """
    Parameters
    ----------
    m : Jan

    Returns
    -------
    day : Day
    """

will work out of the box without having to declare Jan or Day in config. This also works for relative imports.

@lagru lagru added this to the v0.4 milestone Jul 17, 2025
@lagru lagru added the enhancement New feature or request label Jul 17, 2025
@lagru lagru force-pushed the collect-from-imports branch 2 times, most recently from 3a3315a to 033d560 Compare July 22, 2025 20:05
@lagru lagru marked this pull request as draft July 22, 2025 20:06
lagru added 5 commits July 23, 2025 16:26
"from imports" are collected as types within the scope of the containing
module. E.g. "from pathlib import Path" will allow using "Path" inside
the modules scope.

"import" without "from" are collected as scoped type prefixes. Meaning
if a module contains "import scipy as sp", "sp." can be used as a valid
type prefix in that module.
And also improve the class representation and various other things.
`py_import` can already be imported manually in the module's namespace.
In which case `py_import` cannot be formatted as an import and shouldn't
be collected.
@lagru lagru force-pushed the collect-from-imports branch from 033d560 to 945b59e Compare July 23, 2025 15:34
@lagru lagru marked this pull request as ready for review July 23, 2025 15:40
@lagru lagru added the maintenance Keeps the lights on label Jul 23, 2025
@lagru lagru changed the title Collect "from imports" as referencable names for docstrings Use imports to collect (scoped) type information Jul 23, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request maintenance Keeps the lights on
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Make a module's imports reference-able for doctypes?
1 participant