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

Remove sphinx.util.inspect.isNewType #12646

Merged
merged 5 commits into from
Jul 22, 2024

Conversation

AA-Turner
Copy link
Member

No description provided.

@AA-Turner AA-Turner changed the title Deprecate isNewType Remove sphinx.util.inspect.isNewType Jul 22, 2024
@AA-Turner AA-Turner added this to the 8.0.0 milestone Jul 22, 2024
@AA-Turner AA-Turner merged commit 97df13d into sphinx-doc:master Jul 22, 2024
19 checks passed
@AA-Turner AA-Turner deleted the deprecate-isnewtype branch July 22, 2024 16:27
@kiwifb
Copy link

kiwifb commented Jul 29, 2024

Is there a matching documentation? I cannot see anything about this at https://www.sphinx-doc.org/en/master/extdev/deprecated.html Is there anywhere where we can find why it did not go through deprecation and directly to undocumented removal? I just bumped into this while trying to build sagemath documentation with 8.0.0_rc1 after checking that all the documented as removed in 8.0 API are gone from the code.

@AA-Turner
Copy link
Member Author

Hi François, from our perspective this is a purely internal API, note that we don't document it in https://www.sphinx-doc.org/en/master/extdev/index.html. I can add a note to the changelog if useful, perhaps?

A

@kiwifb
Copy link

kiwifb commented Jul 29, 2024

Thanks for the kind answer. It makes sense if it is supposed to be an internal API. sagemath has clearly been using something they should not. To be fair we have been trying to get rid of the old copy of autodoc.py shipped into sagemath and that needs to be changed every major release of sphinx or so.
That'll give me something to do.

@AA-Turner
Copy link
Member Author

AA-Turner commented Jul 29, 2024

See b0485f9 for a migration note.

The full old definition of the function (if you need to vendor it) was:

def safe_getattr(obj: Any, name: str, *defargs: Any) -> Any:
    """A getattr() that turns all exceptions into AttributeErrors."""
    try:
        return getattr(obj, name, *defargs)
    except Exception as exc:
        # sometimes accessing a property raises an exception (e.g.
        # NotImplementedError), so let's try to read the attribute directly
        try:
            # In case the object does weird things with attribute access
            # such that accessing `obj.__dict__` may raise an exception
            return obj.__dict__[name]
        except Exception:
            pass

        # this is a catch-all for all the weird things that some modules do
        # with attribute access
        if defargs:
            return defargs[0]

        raise AttributeError(name) from exc


def isNewType(obj: Any) -> bool:
    """Check the if object is a kind of :class:`~typing.NewType`."""
    if sys.version_info[:2] >= (3, 10):
        return isinstance(obj, typing.NewType)
    __module__ = safe_getattr(obj, '__module__', None)
    __qualname__ = safe_getattr(obj, '__qualname__', None)
    return __module__ == 'typing' and __qualname__ == 'NewType.<locals>.new_type'

A

@kiwifb
Copy link

kiwifb commented Jul 29, 2024

Thanks for all the pointers but I may try something more ambitious (get rid of https://github.com/sagemath/sage/blob/develop/src/sage_docbuild/ext/sage_autodoc.py) and see how hard it is to adapt.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 30, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants